Skip to content

Commit

Permalink
chore: support for multiple account selection
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 1, 2024
1 parent e73cf8f commit d2f9ae6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Support for account selection

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/weby_pilot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .bpi import BpiAPI

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()
Expand Down
30 changes: 25 additions & 5 deletions src/weby_pilot/bpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# -*- coding: utf-8 -*-

from enum import Enum
from time import sleep
from os import environ
from os.path import basename
from datetime import datetime
from typing import IO, Literal, Sequence, Tuple, cast
from typing import IO, Literal, Sequence, cast
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

from .base import WebyAPI
from .common import FileType
Expand Down Expand Up @@ -119,12 +121,14 @@ def download_report(
self,
section: ReportSections = "Extrato Conta",
report_indexes: Sequence[int] = (0,),
account_index: int = 0,
) -> 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)
for report_index in report_indexes:
self.click_extract(row_index=report_index)
docs.append(
Expand All @@ -142,17 +146,21 @@ def download_report(
return docs

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

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

def download_card_report(self, card_index=0, report_indexes: Sequence[int] = (0,)):
Expand Down Expand Up @@ -199,6 +207,18 @@ def select_filters(self, date_range: SelectDateRange, document_type: DocumentTyp
filter = self.get_element(By.XPATH, "//*[@value='Filtrar']")
filter.click()

def select_account(self, index: int = 0, timeout=5.0):
account_element = self.get_element(
By.XPATH, "//div[text()='Conta']/following-sibling::div/*/select"
)
account_select = Select(account_element)
selected_index = account_select.options.index(
account_select.first_selected_option
)
if selected_index != index:
account_select.select_by_index(index)
sleep(timeout)

def click_extract(self, row_index=0, wait_download: bool = True):
open_extract = self.get_element(
By.XPATH,
Expand Down

0 comments on commit d2f9ae6

Please sign in to comment.