Skip to content

Instantly share code, notes, and snippets.

@sam-thecoder
Created August 27, 2018 09:25
Show Gist options
  • Save sam-thecoder/c17861fe22762e6857418058376e8e00 to your computer and use it in GitHub Desktop.
Save sam-thecoder/c17861fe22762e6857418058376e8e00 to your computer and use it in GitHub Desktop.
import requests
import time
import datetime
import pandas as pd
df = pd.DataFrame(columns=['Date', 'Value'])
def data_retriever(sleep=30):
global df
while True:
resp = requests.get('https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=USD')
price = resp.json()['BTC']['USD']
date = datetime.datetime.now().strftime('%d-%m-%Y %H:%M')
df = df.append({'Date': date, 'Value': price}, ignore_index=True)
print(df.shape)
df.to_csv('data/btc-daily.csv', index=False)
time.sleep(sleep)
data_retriever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment