-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchart.py
26 lines (25 loc) · 797 Bytes
/
chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import socket
import sqlite3
import json
db = sqlite3.connect("chart.sqlite")
cur = db.cursor()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("bitcoincharts.com", 27007))
try:
started = False
data = []
while True:
d = s.recv(1)
if d == "{":
started = True
if started:
data.append(d)
if d == "}":
started = False
jdata = json.loads("".join(data))
cur.execute("INSERT INTO chart (timestamp, price, volume, currency, tid, symbol) VALUES (?, ?, ?, ?, ?, ?)", (jdata['timestamp'], jdata['price'], jdata['volume'], jdata['currency'], jdata['tid'], jdata['symbol']))
db.commit()
print "".join(data)
data = []
except KeyboardInterrupt:
pass