Skip to content

Commit

Permalink
fix: issue with investment extracts
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 1, 2024
1 parent 1be7907 commit 5f10132
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

*
* Issue with investment extracts

## [0.1.4] - 2024-10-01

Expand Down
4 changes: 2 additions & 2 deletions src/weby_pilot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from .bpi import BpiAPI

print(BpiAPI().download_account_report(report_indexes=range(0, 2), account_index=1))

print(BpiAPI().download_account_report(report_indexes=range(0, 2)))
# print(BpiAPI().download_account_report(report_indexes=range(0, 2), account_index=1))
# BpiAPI().download_report(section="Extrato Investimento", report_indexes=range(0, 8))
# BpiAPI().download_invoice()
# print(BpiAPI().get_balance())
Expand Down
7 changes: 7 additions & 0 deletions src/weby_pilot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from io import BytesIO
from shutil import rmtree
from typing import IO, Any, Generator, List, Literal
from uuid import uuid4
from time import sleep
Expand Down Expand Up @@ -30,6 +31,7 @@ def __init__(self, headless: bool = False, stable: bool = True):
class WebyAPI:
_driver: Chrome | None = None
_wait: WebDriverWait[Chrome] | None = None
_remove_downloads: bool = False
_downloads_dir: str = abspath("downloads")
_temp_dir: str = abspath("temp")
_last_path: str | None = None
Expand Down Expand Up @@ -64,13 +66,18 @@ def start(self, options: WebyOptions = WebyOptions()):
"safebrowsing.disable_download_protection": True,
},
)

self._driver = Chrome(options=chrome_options)
if options.stable:
self._driver.delete_all_cookies()

self._wait = WebDriverWait(self._driver, MAX_WAIT_TIME)

def stop(self):
if self.driver is not None:
self.driver.quit()
if self._remove_downloads and exists(self._downloads_dir):
rmtree(self._downloads_dir)

def get_element(self, by: str, value: str) -> WebElement:
return self.wait.until(
Expand Down
11 changes: 5 additions & 6 deletions src/weby_pilot/bpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ def download_report(
self,
section: ReportSections = "Extrato Conta",
report_indexes: Sequence[int] = (0,),
account_index: int = 0,
account_index: int | None = None,
) -> Sequence["BpiDocument"]:
docs: list[BpiDocument] = []
with self.driver_ctx():
self.login()
self.select_section("Consultas")
self.select_side_menu(cast(BpiSideSections, section))
self.select_account(account_index)
if account_index is not None:
self.select_account(account_index)
for report_index in report_indexes:
self.click_extract(row_index=report_index)
docs.append(
Expand All @@ -155,12 +156,10 @@ def download_account_report(
)

def download_investing_report(
self, report_indexes: Sequence[int] = (0,), account_index: int = 0
self, report_indexes: Sequence[int] = (0,)
) -> Sequence["BpiDocument"]:
return self.download_report(
section="Extrato Investimento",
report_indexes=report_indexes,
account_index=account_index,
section="Extrato Investimento", report_indexes=report_indexes
)

def download_card_report(
Expand Down

0 comments on commit 5f10132

Please sign in to comment.