- 
      
 - 
        
Save hendrixcosta/86f621d688e0a1248b0449aa5adb8fb6 to your computer and use it in GitHub Desktop.  
    Python - Obtendo o preço do bitcoin
  
        
  
    
      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
    
  
  
    
  | 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