PKZnOM<XXbbscraper/__init__.py """bbscraper""" __version__ = '1.2' from bbscraper.scraper import BancodoBrasilScraper PK"lOM|%%bbscraper/__main__.pyfrom bbscraper import cli cli.main()PK"lOMQobbscraper/cli.py"""Comand Line Interface""" import argparse from getpass import getpass from tabulate import tabulate from bbscraper.scraper import BancodoBrasilScraper def csv(data): lines = (','.join((str(col) for _, col in row.items()) ) for row in data) return "\n".join(lines) def table(data): return tabulate(data, headers="keys", floatfmt='.2f', tablefmt="fancy_grid") def main(): parser = argparse.ArgumentParser( description='Programa para parsear transações financeiras do Banco do Brasil') parser.add_argument( '--agencia', '-a', help='Número da agência do Banco do Brasil, no formato 00000', required=True) parser.add_argument( '--conta', '-c', help='Número da conta do Banco do Brasil, no formato 00000', required=True) parser.add_argument('--senha', '-s', help='Senha da Conta do Banco do Brasil') parser.add_argument( '--dias', help='Log de Transações dos últimos dias. default é 15 dias.', default=15, type=int) parser.add_argument( '--saldo', dest='saldo', action='store_true', help='Busca somente o saldo da conta.') parser.add_argument( '--extrato', dest='extrato', action='store_true', help='Busca o extrato da conta.') parser.add_argument( '--csv', help='Imprime os dados em CSV.', dest='output', action='store_const', const=csv, default=table) args = parser.parse_args() if not (args.saldo or args.extrato): parser.exit(0, "Indique a operação: --saldo ou --extrato\n") senha = args.senha or getpass("Digite sua senha do Banco do Brasil: ") if not senha: parser.exit(0, "Você não digitou a senha!\n") if len(senha) < 8: parser.exit(0, "Digite a senha de 8 dígitos!\n") output = args.output # csv or table (default) bb = BancodoBrasilScraper(args.agencia, args.conta, senha) print(bb) assert bb.login() print() if args.saldo: print(f'Saldo: R${bb.saldo()}') if args.extrato: print(output(bb.extrato())) PK"lOM-bbscraper/scraper.py"""Scraper do Banco do Brasil """ from datetime import datetime from decimal import Decimal from random import randint import requests from requests.adapters import HTTPAdapter from bbscraper.urls import API_ENDPOINT, HASH_URL, LOGIN_URL, SALDO_URL, TRANSACOES_URL class MobileSession(requests.Session): def __init__(self): super().__init__() self.mount(API_ENDPOINT, HTTPAdapter(max_retries=32, pool_connections=50, pool_maxsize=50)) self.headers.update({ 'User-Agent' : 'Apple; iPad2,1; iPhone OS; 9.3.5; 13G36; mov-iphone-app; 3.42.0.1; pt_BR; 00; 00; WIFI; isSmartphone=false;', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }) class BancodoBrasilScraper: """Scraper do Banco do Brasil""" def __init__(self, agencia, conta, senha): self.agencia = agencia self.conta = conta self.senha = senha self.id_dispositivo = '000000000000000' self.ida = '00000000000000000000000000000000' self.nick = f'NICKRANDOM.{randint(1000, 99999)}' self.idh = '' self.mci = '' self.segmento = '' # PESSOA FISICA self.session = MobileSession() def login(self): hash_data = { 'hash': '', 'idh': '', 'id': self.ida, 'idDispositivo': self.id_dispositivo, 'apelido': self.nick } response = self.session.post(HASH_URL, data=hash_data) self.idh = response.content login_data = { 'idh': self.idh, 'senhaConta': self.senha, 'apelido': self.nick, 'dependenciaOrigem': self.agencia, 'numeroContratoOrigem': self.conta, 'idRegistroNotificacao': '', 'idDispositivo': self.id_dispositivo, 'titularidade': 1 } response = self.session.post(LOGIN_URL, data=login_data) if bytes('CODIGO NAO CONFERE', 'utf-8') in response.content or bytes('G176-845', 'utf-8') in response.content: print('[!] Login failed, invalid credentials') elif bytes('SENHA BLOQUEADA', 'utf-8') in response.content: print('[!] Login failed, account locked') try: json_response = response.json()['login'] except json.decoder.JsonDecodeError as e: print("Expecting Value") #else: #print(f'json response: {json_response}') #print(f"(, , )") return json_response def saldo(self): saldo_data = { 'servico/ServicoSaldo/saldo': '', 'idh': self.idh, 'idDispositivo': self.id_dispositivo, 'apelido': self.nick } response = self.session.post(SALDO_URL, data=saldo_data) json_response = response.json()['servicoSaldo'] json_saldo = json_response['saldo'] saldo = Decimal(json_saldo.split()[0].replace('.', '').replace(',', '.')) * -1 if json_saldo.split()[-1] == 'D' else float(json_saldo.split()[0].replace('.', '').replace(',', '.')) return saldo def extrato(self): payload = { 'abrangencia': 8, 'idh': self.idh, 'idDispositivo': self.id_dispositivo, 'apelido': self.nick } response = self.session.post(TRANSACOES_URL, data=payload) json_response = response.json() sessoes = json_response['conteiner']['telas'][0]['sessoes'] transacoes = [] for s in sessoes: if s['TIPO'] == 'sessao' and s.get('cabecalho'): if s['cabecalho'].startswith('M') and 'ncia:' in s['cabecalho']: month = s['cabecalho'].split()[-3:] for tt in s['celulas']: if tt['TIPO'] == 'celula': if len(tt['componentes']) == 3 and tt['componentes'][0]['componentes'][0]['texto'] != 'Dia': description = tt['componentes'][1]['componentes'][0]['texto'] date = self.parse_date(tt['componentes'][0]['componentes'][0]['texto'], month[0], month[2]).date() value = Decimal(tt['componentes'][2]['componentes'][0]['texto'].split()[0].replace('.', '').replace(',', '.')) sign = '-' if tt['componentes'][2]['componentes'][0]['texto'].split()[-1] == 'D' else '+' raw = tt['componentes'] transacoes.append({'description': description, 'date': date, 'value': value}) # , 'sign': sign, 'raw': raw else: continue elif s['cabecalho'].startswith('Informa') and s['cabecalho'].endswith('es adicionais'): for tt in s['celulas']: if tt['TIPO'] == 'celula': if tt['componentes'][0]['componentes'][0]['texto'] == 'Juros': val = Decimal(tt['componentes'][1]['componentes'][0]['texto'].split()[-1].replace('.', '').replace(',', '.')) return transacoes def parse_date(self, day, month, year): m2n = { 'Janeiro': 1, 'Fevereiro': 2, 'Marco': 3, 'Março': 3, 'Abril': 4, 'Maio': 5, 'Junho': 6, 'Julho': 7, 'Agosto': 8, 'Setembro': 9, 'Outubro': 10, 'Novembro': 11, 'Dezembro': 12 } return datetime.strptime('{}/{}/{}'.format(day, m2n[month], year), '%d/%m/%Y') def __str__(self): return f"" PK"lOM0sbbscraper/urls.pyAPI_ENDPOINT = 'https://mobi.bb.com.br/mov-centralizador/' HASH_URL = 'https://mobi.bb.com.br/mov-centralizador/hash' LOGIN_URL = 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoLogin/login' SALDO_URL = 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoSaldo/saldo' TRANSACOES_URL = 'https://mobi.bb.com.br/mov-centralizador/servico/ExtratoDeContaCorrente/extrato' # Essas url não são utilizadas pelo script do Kamus, eu preciso entender para que servem POST_LOGIN_WARMUP_URL1= 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoVersionamento/servicosVersionados' POST_LOGIN_WARMUP_URL2 = 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoVersaoCentralizador/versaoDaAplicacaoWeb' POST_LOGIN_WARMUP_URL3 = 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoMenuPersonalizado/menuPersonalizado' POST_LOGIN_WARMUP_URL4 = 'https://mobi.bb.com.br/mov-centralizador/servico/ServicoMenuTransacoesFavoritas/menuTransacoesFavoritas'PK!HPȾ)0(bbscraper-1.2.dist-info/entry_points.txtN+I/N.,()JJ2 Rl,L<..PK"lOMpbbscraper-1.2.dist-info/LICENSE GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. PK!H>*RQbbscraper-1.2.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UrPK!HR ] bbscraper-1.2.dist-info/METADATAW]o7}篸i.Njq:if( 9lP@Ul%Gu@Ğ!y=RY ښ =3٨ tUNG<6tQE+Zxa6ci*[+}ʏggRUjZS]*!٫4uv2Kvj'lyo|e)^Jm+w}/Sv !x8RHeBz¯.*{aa- ʏZնmp΃ dBfVdeclPج&A漽u=TEXieJi#MeaሏN։nsCCW{u~BӶuv x~Ns4A,k]Btx3OYFԜͬ q*zOC:N66˛%?%Rdk" Y,i7ӇiYh-& R*K;=[V:Is/# `}pKJ? qhK kD1ݻwe/mwt#۟b >%])-R*,~wͳ@RGR{*4z xKx;wxBU  PNIu{{UByRTxP]:O:ɓ#1ik|aYl 9kNsζl'ITQOxQDaS(αIkغ?'An[d\uI *-^J7j ͜p{ *ǝn eڬnD$%$WActHuXq:tz| ɿѨ&d3mD* P?Z Um*Vi%zIo;\'bY%h] &A!·NY"-}'St{> + 09Q\n~ĄSM};G"&G@Ucv@+qV3G١4wLQ^x6*`;B`O D6]t0ٚD }o#^̊q& */PK!H^ibbscraper-1.2.dist-info/RECORD}ɖ@}? "bh,D@DA6FL"Y=Ӵp3Q8޴3~}-&^cƺ 1GQf}WtNHGXD4AC)P pqݎ"Xqeewbp!^LvTiv8h ڜJM޼՗D0+?:ŵ8wJnd !J R @`oD2_I7ΘQfH{}ݹ[]:ݑTT/Df~ Q]6E=9nTfx/l]7 ?߶jpJhڽ),,5:TuT bY1l%t<%Ϡ`L6 -+! < nԽKPȁM*xL6'ip{;9q)Bzouh/I~&An H vf!o %#8?:FPKZnOM<XXbbscraper/__init__.pyPK"lOM|%%bbscraper/__main__.pyPK"lOMQobbscraper/cli.pyPK"lOM- bbscraper/scraper.pyPK"lOM0sM bbscraper/urls.pyPK!HPȾ)0(?$bbscraper-1.2.dist-info/entry_points.txtPK"lOMp$bbscraper-1.2.dist-info/LICENSEPK!H>*RQBbbscraper-1.2.dist-info/WHEELPK!HR ] [Cbbscraper-1.2.dist-info/METADATAPK!H^iJbbscraper-1.2.dist-info/RECORDPK L