Created
July 6, 2017 20:38
-
-
Save RChloe/5dc18d02914289bd06aaa5191931d60c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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