Skip to content

Instantly share code, notes, and snippets.

@danizavtz
Created January 10, 2023 16:53
Show Gist options
  • Save danizavtz/d9b1828502bd358caed2bafa043c0a4a to your computer and use it in GitHub Desktop.
Save danizavtz/d9b1828502bd358caed2bafa043c0a4a to your computer and use it in GitHub Desktop.
import requests, pandas as pd, json
from requests import RequestException
def getAPI():
url = "https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoMoedaPeriodo(moeda=@moeda,dataInicial=@dataInicial,dataFinalCotacao=@dataFinalCotacao)?@moeda='USD'&@dataInicial='01-01-2022'&@dataFinalCotacao='01-05-2023'&$top=100000000&$format=json&$select=paridadeCompra,paridadeVenda,cotacaoCompra,cotacaoVenda,dataHoraCotacao,tipoBoletim"
payload={}
headers = {}
try:
response = requests.request("GET", url, headers=headers, data=payload)
apenasAtributoValue = response.json()['value'] #esta linha faz o que deseja
df = pd.DataFrame.from_dict(apenasAtributoValue)
print(df)
except RequestException as error:
print(error)
getAPI()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment