Skip to content

Instantly share code, notes, and snippets.

@christ776
Created April 29, 2019 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christ776/6ef926648ed0aaef55bb7b331a4cb8f0 to your computer and use it in GitHub Desktop.
Save christ776/6ef926648ed0aaef55bb7b331a4cb8f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
from requests.exceptions import ConnectionError
import json
import locale
from bs4 import Tag, NavigableString, BeautifulSoup
"""
Set locale to es_ES
"""
locale.setlocale(locale.LC_ALL, 'es_ES')
def dolar_galicia():
url = 'https://www.bancogalicia.com/cotizacion/cotizar?currencyId=02&quoteType=SU&quoteId=999'
try:
resp = requests.get(url)
except ConnectionError as error:
print(error)
return
obj = resp.json()
if 'error' in obj:
print ('Valor no disponible')
return
print_quotation('Galicia', ( locale.atof(obj['buy']), locale.atof(obj['sell'])))
def dolar_BNA():
url = 'http://www.bna.com.ar/Personas'
resp = requests.get(url)
resp.raise_for_status()
parsedHTML = BeautifulSoup(resp.text, "html.parser")
panel_monedas = parsedHTML.select('#billetes')[0]
dolar = panel_monedas.select('.tit')[0]
xx = list(dolar.parent.children)
""" Remove '\n' by filtering out NavigableString objects who represent carriage return"""
_, buy, sell = list(filter(lambda x: not isinstance(x, NavigableString), xx))
print_quotation('BNA', (locale.atof(buy.text), locale.atof(sell.text)))
def print_quotation(bankName, quote):
print(bankName.center(20, '='))
print('Compra | Venta')
print("{0:.2f} {1:.2f}".format(quote[0], quote[1]))
if __name__ == "__main__":
dolar_galicia()
dolar_BNA()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment