Skip to content

Instantly share code, notes, and snippets.

@arthurbarros
Last active March 22, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurbarros/9fbe4e979fd6fd3a0638f973c022c3c9 to your computer and use it in GitHub Desktop.
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
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={}&currencies={}'.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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment