Skip to content

Instantly share code, notes, and snippets.

@marcoscastro
Last active October 20, 2020 11:38
Show Gist options
  • Save marcoscastro/4ff00673dd04f1193070e9f0a1df28ee to your computer and use it in GitHub Desktop.
Save marcoscastro/4ff00673dd04f1193070e9f0a1df28ee to your computer and use it in GitHub Desktop.
Python - Obtendo o preço do bitcoin
from urllib.request import Request, urlopen
import json, time
def obter_valor():
url = "http://api.coindesk.com/v1/bpi/currentprice.json"
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
response = urlopen(req).read()
data = json.loads(response.decode('utf-8'))
valor = float(data['bpi']['USD']['rate'].replace(',', ''))
return valor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment