Created
August 27, 2018 09:25
-
-
Save sam-thecoder/c17861fe22762e6857418058376e8e00 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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