Skip to content

Instantly share code, notes, and snippets.

@RChloe
Created July 6, 2017 20:38
Show Gist options
  • Save RChloe/5dc18d02914289bd06aaa5191931d60c to your computer and use it in GitHub Desktop.
Save RChloe/5dc18d02914289bd06aaa5191931d60c to your computer and use it in GitHub Desktop.
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