diff --git a/.gitignore b/.gitignore index 521a85f..0baf30d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +error_download_lcl.png geckodriver.log # Created by https://www.gitignore.io/api/osx,pycharm,python diff --git a/.tool-versions b/.tool-versions index 2ab8199..ccfa51c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ python 3.11.2 +poetry latest diff --git a/error_download_lcl.png b/error_download_lcl.png deleted file mode 100644 index 2c2ab6e..0000000 Binary files a/error_download_lcl.png and /dev/null differ diff --git a/ofx_processor/downloaders/lcl.py b/ofx_processor/downloaders/lcl.py index 9dedb58..57dfdb4 100644 --- a/ofx_processor/downloaders/lcl.py +++ b/ofx_processor/downloaders/lcl.py @@ -1,4 +1,4 @@ -import os +import datetime import time from pathlib import Path @@ -27,7 +27,7 @@ class LclDownloader: download_folder = Path.home() / "Downloads" self.download_folder = download_folder.resolve() options = webdriver.FirefoxOptions() - options.headless = True + options.add_argument("-headless") options.set_preference("browser.download.dir", str(self.download_folder)) options.set_preference( "browser.helperApps.neverAsk.saveToDisk", "application/x-ofx" @@ -72,20 +72,19 @@ class LclDownloader: click.secho("No welcome screen found.", fg="blue") retry = False - try: - self._click(By.CSS_SELECTOR, ".burger-menu-content") - self._click(By.CSS_SELECTOR, ".return-legacy-button") - click.secho("Going back to legacy version...", fg="blue") - except NoSuchElementException: - click.secho("Probably already on legacy version.", fg="blue") + self._click(By.CLASS_NAME, "extended-zone") + self._click(By.ID, "export-button") - click.secho("Navigating through archives...", fg="blue") - self._click(By.ID, "linkSynthese") - self._click(By.CLASS_NAME, "picDl") - self._select(By.ID, "change", index=1) - self._select(By.ID, "DS", index=20) - self._click(By.ID, "MON04") - self._click(By.ID, "Valider") + end = datetime.date.today() - datetime.timedelta(days=1) + start = end - datetime.timedelta(days=9) + + self._type_nth(By.CSS_SELECTOR, "input.range-picker-input", 0, start.strftime("%d/%m/%Y")) + self._type_nth(By.CSS_SELECTOR, "input.range-picker-input", 1, end.strftime("%d/%m/%Y")) + + self._click(By.CSS_SELECTOR, "ui-desktop-select button") + self._click_nth(By.CSS_SELECTOR, "ui-select-list ul li", 2) + + self._click(By.CLASS_NAME, "download-button") click.secho("Found it!", fg="green") selenium.get("about:downloads") return self._get_last_download_file_name() @@ -93,9 +92,15 @@ class LclDownloader: def _click(self, by: By, value: str): self.selenium.find_element(by, value).click() + def _click_nth(self, by: By, value: str, idx: int): + self.selenium.find_elements(by, value)[idx].click() + def _select(self, by: By, value: str, index: int): Select(self.selenium.find_element(by, value)).select_by_index(index) + def _type_nth(self, by: By, value: str, idx: int, value_to_type: str): + self.selenium.find_elements(by, value)[idx].send_keys(value_to_type) + def _get_last_download_file_name(self, wait_seconds: int = 30): end_time = time.time() + wait_seconds while time.time() < end_time: diff --git a/pyproject.toml b/pyproject.toml index 0db5d10..d06b528 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ofx-processor" -version = "4.4.6" +version = "4.5.0" description = "Personal ofx processor" readme = "README.md" authors = ["Gabriel Augendre "]