Last active
February 3, 2021 04:03
-
-
Save sidward35/70cda0fc14d674818121e7d0c2b68fa4 to your computer and use it in GitHub Desktop.
Fetches the current Bitcoin price in USD and saves it to a local file
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 | |
import json | |
import time | |
from datetime import datetime | |
while True: | |
response = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json') | |
price = response.json().get('bpi').get('USD').get('rate') | |
now = datetime.now() | |
dt_string = now.strftime("%m/%d/%Y %H:%M:%S") | |
result = '[' + dt_string + '] BTC Price: $' + price | |
print(result) | |
file1 = open('btc_price_history.txt', 'a') | |
file1.write(result+'\n') | |
file1.close() | |
time.sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment