Created
October 28, 2010 13:19
-
-
Save ihercowitz/651328 to your computer and use it in GitHub Desktop.
Script para obter o saldo do Visa Vale
This file contains 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
import urllib2, urllib, sys | |
from BeautifulSoup import BeautifulSoup | |
import re | |
class VisaVale(): | |
def get_visavale_informations(self,visa): | |
url = 'http://www.cbss.com.br/inst/convivencia/SaldoExtrato.jsp' | |
data = urllib.urlencode([('numeroCartao',visa),('primeiroAcesso','S')]) | |
request = urllib2.Request(url) | |
response = urllib2.urlopen(request, data) | |
data = response.read() | |
soup = BeautifulSoup(data) | |
self.data_consulta = soup('table')[0]('td')[1].string | |
self.numero_cartao = soup('table')[0]('td')[3].string | |
self.data_ultima_disponibilizacao = soup('table')[0]('td')[5].string | |
self.valor_ultima_disponibilizacao = re.split(':',soup('table')[0]('td')[6].string)[1] | |
self.data_proxima_disponibilizacao = soup('table')[0]('td')[8].string | |
self.valor_proxima_disponibilizacao = re.split(':', soup('table')[0]('td')[9].string)[1] | |
self.valor_atual_disponivel = soup('table')[3]('td')[1].string | |
def show_informations(self): | |
print 'Consulta em %s\n' %self.data_consulta | |
print 'Em %s foi disponibilizado %s\n' %(self.data_ultima_disponibilizacao, | |
self.valor_ultima_disponibilizacao) | |
if self.data_proxima_disponibilizacao != '' and self.valor_proxima_disponibilizacao != '': | |
print 'A proxima recarga sera em %s no valor de %s\n' %(self.data_proxima_disponibilizacao, | |
self.valor_proxima_disponibilizacao) | |
print 'Voce possui %s de credito disponivel\n' %self.valor_atual_disponivel | |
if __name__=="__main__": | |
args = sys.argv[1:] | |
try: | |
if args[0] == "": | |
print "Como usar: python visaVale.py <numero visa vale>" | |
sys.exit(0) | |
except: | |
print "Como usar: python visaVale.py <numero visa vale>" | |
sys.exit(0) | |
visa = VisaVale() | |
visa.get_visavale_informations(args[0]) | |
visa.show_informations() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment