Last active
March 22, 2018 20:27
-
-
Save arthurbarros/9fbe4e979fd6fd3a0638f973c022c3c9 to your computer and use it in GitHub Desktop.
Get all votes from the current day from CryptoPanic for a given currency
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 requests | |
def get_url(url, news): | |
res = requests.get(url) | |
for new in res.json()['results']: | |
news.append(new) | |
if res.json()['next']: | |
news = get_url(res.json()['next'], news) | |
return news | |
def get_votes(auth_key, currency): | |
url = 'https://cryptopanic.com/api/posts/?auth_token={}¤cies={}'.format(auth_key, currency) | |
news = [] | |
news = get_url(url, news) | |
overall = { k: 0 for k in news[0]['votes'].keys() } | |
for k in overall.keys(): | |
for n in news: | |
overall[k] += n['votes'][k] | |
return overall | |
if __name__ == '__main__': | |
# you can get it at https://cryptopanic.com/about/api/ | |
AUTH_TOKEN = 'AUTH_TOKEN' | |
CURRENCY_CODE = 'BTC' | |
votes = get_votes(AUTH_TOKEN, CURRENCY_CODE) | |
print(votes) |
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
requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment