Skip to content

Instantly share code, notes, and snippets.

@ypwhs
Created March 18, 2017 01:47
Show Gist options
  • Save ypwhs/331cc8aacc030b2124c94a3e5d32a2aa to your computer and use it in GitHub Desktop.
Save ypwhs/331cc8aacc030b2124c94a3e5d32a2aa to your computer and use it in GitHub Desktop.
ETH robot
# coding: utf-8
import numpy as np
import requests
import datetime
import itchat
import time
import os
sensitive = 0.5
timeout = 10
last = 0
online = True
api_url = 'https://api.coinbase.com/v2/prices/ETH-USD/spot'
def exited():
online = False
itchat.auto_login(hotReload=True, enableCmdQR=2, exitCallback=exited)
chatroom = itchat.search_chatrooms('ETH')[0]['UserName']
while online:
try:
data = requests.get(api_url, timeout=timeout).json()['data']['amount']
msg = u'%s 价格: %s' % (datetime.datetime.today().strftime('%H:%M:%S'), data)
p = float(data)
print msg
if abs(p - last) > sensitive:
last = p
itchat.send(msg, toUserName=chatroom)
except Exception as e:
print e
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment