implement download from new lcl interface

This commit is contained in:
Gabriel Augendre 2024-10-14 19:55:37 +02:00
parent a4eb23280f
commit 8ef7829b73
5 changed files with 23 additions and 16 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
error_download_lcl.png
geckodriver.log geckodriver.log
# Created by https://www.gitignore.io/api/osx,pycharm,python # Created by https://www.gitignore.io/api/osx,pycharm,python

View file

@ -1 +1,2 @@
python 3.11.2 python 3.11.2
poetry latest

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

View file

@ -1,4 +1,4 @@
import os import datetime
import time import time
from pathlib import Path from pathlib import Path
@ -27,7 +27,7 @@ class LclDownloader:
download_folder = Path.home() / "Downloads" download_folder = Path.home() / "Downloads"
self.download_folder = download_folder.resolve() self.download_folder = download_folder.resolve()
options = webdriver.FirefoxOptions() options = webdriver.FirefoxOptions()
options.headless = True options.add_argument("-headless")
options.set_preference("browser.download.dir", str(self.download_folder)) options.set_preference("browser.download.dir", str(self.download_folder))
options.set_preference( options.set_preference(
"browser.helperApps.neverAsk.saveToDisk", "application/x-ofx" "browser.helperApps.neverAsk.saveToDisk", "application/x-ofx"
@ -72,20 +72,19 @@ class LclDownloader:
click.secho("No welcome screen found.", fg="blue") click.secho("No welcome screen found.", fg="blue")
retry = False retry = False
try: self._click(By.CLASS_NAME, "extended-zone")
self._click(By.CSS_SELECTOR, ".burger-menu-content") self._click(By.ID, "export-button")
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")
click.secho("Navigating through archives...", fg="blue") end = datetime.date.today() - datetime.timedelta(days=1)
self._click(By.ID, "linkSynthese") start = end - datetime.timedelta(days=9)
self._click(By.CLASS_NAME, "picDl")
self._select(By.ID, "change", index=1) self._type_nth(By.CSS_SELECTOR, "input.range-picker-input", 0, start.strftime("%d/%m/%Y"))
self._select(By.ID, "DS", index=20) self._type_nth(By.CSS_SELECTOR, "input.range-picker-input", 1, end.strftime("%d/%m/%Y"))
self._click(By.ID, "MON04")
self._click(By.ID, "Valider") 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") click.secho("Found it!", fg="green")
selenium.get("about:downloads") selenium.get("about:downloads")
return self._get_last_download_file_name() return self._get_last_download_file_name()
@ -93,9 +92,15 @@ class LclDownloader:
def _click(self, by: By, value: str): def _click(self, by: By, value: str):
self.selenium.find_element(by, value).click() 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): def _select(self, by: By, value: str, index: int):
Select(self.selenium.find_element(by, value)).select_by_index(index) 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): def _get_last_download_file_name(self, wait_seconds: int = 30):
end_time = time.time() + wait_seconds end_time = time.time() + wait_seconds
while time.time() < end_time: while time.time() < end_time:

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "ofx-processor" name = "ofx-processor"
version = "4.4.6" version = "4.5.0"
description = "Personal ofx processor" description = "Personal ofx processor"
readme = "README.md" readme = "README.md"
authors = ["Gabriel Augendre <gabriel@augendre.info>"] authors = ["Gabriel Augendre <gabriel@augendre.info>"]