Created
March 2, 2020 18:58
-
-
Save maurobaraldi/739f0c956ca9ab08ecb847b90b4cd18d to your computer and use it in GitHub Desktop.
Cotação do Dolar Comercial e Euro via API do UOL economia.
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
#!/usr/bin/env python3 | |
from datetime import datetime | |
from json import loads | |
from urllib.request import urlopen | |
request = urlopen('https://api.cotacoes.uol.com/currency/intraday/list?currency=1&fields=bidvalue,date').read() | |
price = loads(request)['docs'][0] | |
price['date'] = datetime.strptime(price['date'], '%Y%m%d%H%M%S').strftime('%d/%m/%Y às %H:%M:%S') | |
if __name__ == '__main__': | |
print('Dolar Comercial em {date}: {bidvalue}'.format(**price)) |
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
#!/usr/bin/env python3 | |
from datetime import datetime | |
from json import loads | |
from urllib.request import urlopen | |
request = urlopen('https://api.cotacoes.uol.com/currency/intraday/list?currency=5&fields=bidvalue,date').read() | |
price = loads(request)['docs'][0] | |
price['date'] = datetime.strptime(price['date'], '%Y%m%d%H%M%S').strftime('%d/%m/%Y às %H:%M:%S') | |
if __name__ == '__main__': | |
print('Euro em {date}: {bidvalue}'.format(**price)) |
@wilsonhipolito acho que o docs array ja vem ordenado por data, nao?
Oi estou procurando um endereço de material de referência dessa API,vocês podem me ajudar ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oneliner tosco em bash xD :
dá p/ criar um alias :)