Skip to content

Commit

Permalink
Fix authentication (#159)
Browse files Browse the repository at this point in the history
- Remove the first and second authentication steps
- Remove HomePage
  • Loading branch information
lucasrcezimbra committed Dec 13, 2021
1 parent e7131db commit d7da8e6
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 4,379 deletions.
25 changes: 1 addition & 24 deletions pyitau/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import requests
from bs4 import BeautifulSoup

from pyitau.pages import (FirstRouterPage, HomePage, PasswordPage,
SecondRouterPage)
from pyitau.pages import FirstRouterPage, PasswordPage, SecondRouterPage

ITAU_URL = 'https://www.itau.com.br'
ROUTER_URL = 'https://internetpf5.itau.com.br/router-app/router'


Expand All @@ -29,8 +27,6 @@ def __init__(self, agency, account, account_digit, password):
}

def authenticate(self):
self._authenticate0()
self._authenticate1()
self._authenticate2()
self._authenticate3()
self._authenticate4()
Expand Down Expand Up @@ -76,25 +72,6 @@ def get_statements(self):
ROUTER_URL, data={'periodoConsulta': 90}, headers={'op': op5})
return response.json()

def _authenticate0(self):
response = self._session.get(ITAU_URL)
page = HomePage(response.text)
self._id = page.id
self._op1 = page.op

def _authenticate1(self):
data = {
'id': self._id,
'op': self._op1,
'agencia': self.agency,
'conta': self.account,
'dac': self.account_digit,
'tipousuario': 'X',
'origem': 'H'
}
url = 'https://bankline.itau.com.br/GRIPNET/bklcom.dll'
self._session.post(url, data=data)

def _authenticate2(self):
data = {
'portal': '005',
Expand Down
30 changes: 0 additions & 30 deletions pyitau/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
from bs4 import BeautifulSoup


class HomePage:
"""
Página inicial do Itaú. Contém formulário com Agência e Conta.
Utilizada para extrair informações do formulário de login.
"""
def __init__(self, response_text):
self._soup = BeautifulSoup(response_text, features='html.parser')

@property
def _form(self):
"""
Formulário de login com os campos Agência e Conta
"""
return self._soup.find('form', attrs={'name': 'banklineAgConta'})

@property
def id(self):
"""
Campo id do formulário de Agência/Conta
"""
return self._form.find('input', attrs={'name': 'portal'}).attrs['value']

@property
def op(self):
"""
Campo op do formulário de Agência/Conta
"""
return self._form.find('input', attrs={'name': 'tipoLogon'}).attrs['value']


class FirstRouterPage:
"""
Primeira página após enviar o formulário de Agência e Conta.
Expand Down
7 changes: 0 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ def itau():
return Itau(agency, account, account_digit, password)


@pytest.fixture
def response_authenticate0():
with open('./tests/responses/authenticate0.html') as file:
body = file.read()
return body


@pytest.fixture
def response_authenticate2():
with open('./tests/responses/authenticate2.html') as file:
Expand Down

0 comments on commit d7da8e6

Please sign in to comment.