Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Updates the price of BTC in any time interval you request
- #Can overflow
- #V1
- #Thank you MarshallCat94 For Your Help, You Helped Me Learn A Lot!
- import requests
- import time
- while True:
- time.sleep(1)
- response = requests.get("http://api.coindesk.com/v1/bpi/currentprice.json")
- bitcoin_data = response.json()
- bitcoin_price = bitcoin_data['bpi']['USD']['rate_float']
- updated_epoch = bitcoin_data['time']['updated']
- updated_epoch = time.mktime(time.strptime(updated_epoch, "%b %d, %Y %H:%M:%S UTC"))
- updated_time = time.strftime("%H:%M:%S %d/%m/%Y", time.gmtime(updated_epoch))
- print("Bitcoin Price: {price:.2f} $\r\nThis information was updated on {time} UTC".format(price=bitcoin_price, time=updated_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement