Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import urllib.request
import urllib.parse
import json
# --------- User Settings ---------
BUCKET_KEY = "cryptoprice"
ACCESS_KEY = "YOUR_ACCESS_KEY"
# ---------------------------------
def get_conditions():
api_conditions_url = "https://min-api.cryptocompare.com" + "/data/pricemulti?fsyms=ETH,BTC,LTC&tsyms=USD,EUR"
try:
f = urllib.request.urlopen(api_conditions_url)
except:
print("Failed to get conditions")
return False
json_conditions = f.read()
f.close()
return json.loads(json_conditions)
conditions = get_conditions()
if (conditions != False):
payload = urllib.parse.urlencode({'ETH USD':conditions['ETH']['USD'],'BTC USD':conditions['BTC']['USD'],'LTC USD':conditions['LTC']['USD'],'ETH EUR':conditions['ETH']['EUR'],'BTC EUR':conditions['BTC']['EUR'],'LTC EUR':conditions['LTC']['EUR']})
payload = payload.encode('ascii')
url = 'https://groker.initialstate.com/api/events?accessKey=' + ACCESS_KEY + '&bucketKey=' + BUCKET_KEY
urllib.request.urlopen(url,payload)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment