コード例 #1
0
ファイル: price.py プロジェクト: kuopo/bitcoin
import requests
import json
import time

import sys
#sys.path.append("..")
from pubsub_client import MsgHub

msghub = MsgHub("pubsub.msghub.io", 443, secure=True)
#msghub = MsgHub("pubsub.msghub.io", 58080)
#msghub = MsgHub("198.199.97.15", 12345)

current = int(round(time.time() * 1000))
msghub.erase('bitcoin', {"timeframe": {"max": current - 10800000}})
count = 0

while True:
    try:
        r = requests.get('http://data.mtgox.com/api/1/BTCUSD/ticker', timeout=5)
    
        _current = int(json.loads(r.text)['return']['now']) / 1000
        _price = json.loads(r.text)['return']['last_local']['display']
    
        if _current > current:
            current = _current
            print str(int(_current)) + ", " + _price
            msghub.publish("bitcoin", json.loads(r.text), True)
            msghub.save("bitcoin", json.loads(r.text))

            count = count + 1
コード例 #2
0
ファイル: keypress.py プロジェクト: kuopo/keypress
import termios, fcntl, sys, os
import json

#sys.path.append("./pubsub")
from pubsub_client import MsgHub


#msghub = MsgHub("pubsub.msghub.io", 443, secure=True)
msghub = MsgHub("https://pubsub.msghub.io", 443)
#msghub = MsgHub("pubsub.msghub.io", 12345)

def cb(ch, msg):
    handle_keypress(msg['ch'])

msghub.subscribe("keypress", cb)


def handle_keypress(ch):
    if ch == '\x7f':
        sys.stdout.write('\033[1D \033[1D')
    elif ch == '\x1b':
        pass
    else:
        sys.stdout.write(ch)

fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)