Created
February 13, 2014 23:09
-
-
Save drgarcia1986/8985885 to your computer and use it in GitHub Desktop.
Classe feita em Python para recuperar a cotação de algumas moedas estrangeiras baseada nas versões brasileiras do site CashCash.cc
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
__author__ = 'diego.garcia' | |
import urllib.request as req | |
import re | |
class Cotacao: | |
def __get_cotacao(self, url, regex='^.*nacional" value="([0-9,]+)"'): | |
pagina = req.urlopen(url) | |
s = pagina.read().decode('utf-8') | |
m = re.match(regex, s, re.DOTALL) | |
if m: | |
return float(m.group(1).replace(',', '.')) | |
else: | |
return 0 | |
def dolar(self): | |
return self.__get_cotacao('http://dolarhoje.com/') | |
def euro(self): | |
return self.__get_cotacao('http://eurohoje.com/') | |
def libra(self): | |
return self.__get_cotacao('http://librahoje.com/') |
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
__author__ = 'diego.garcia' | |
import cotacao as cot | |
cotacao = cot.Cotacao() | |
print('Hoje estamos com as seguintes contações de moedas estrangeiras') | |
print('Dolar: R${}'.format(cotacao.dolar())) | |
print('Euro: R${}'.format(cotacao.euro())) | |
print('Libra: R${}'.format(cotacao.libra())) | |
input('Pressione uma tecla para sair...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment