aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/report_ops/scotia.py38
1 files changed, 16 insertions, 22 deletions
diff --git a/python/report_ops/scotia.py b/python/report_ops/scotia.py
index 20e64ecd..869994b8 100644
--- a/python/report_ops/scotia.py
+++ b/python/report_ops/scotia.py
@@ -14,16 +14,8 @@ from serenitas.analytics.dates import prev_business_day
logger = logging.getLogger(__name__)
-@contextmanager
-def quit_driver(driver):
- try:
- yield driver
- finally:
- driver.quit()
-
-
def download_report(account_username, password, report_dir, workdate):
- with quit_driver(create_driver(report_dir)) as driver:
+ with create_driver(report_dir) as driver:
login(driver, account_username, password)
navigate_to_inbox(driver, workdate)
attachment_element = get_attachment_element(driver)
@@ -73,6 +65,7 @@ def get_attachment_element(driver):
return driver.find_element(By.CLASS_NAME, "zmessage-attachment-link")
+@contextmanager
def create_driver(download_dir):
options = Options()
options.add_argument("--headless")
@@ -82,24 +75,25 @@ def create_driver(download_dir):
fp.set_preference(
"browser.helperApps.neverAsk.saveToDisk", "application/octet-stream"
)
- return webdriver.Firefox(
+ driver = webdriver.Firefox(
firefox_profile=fp,
options=options,
service_log_path="/home/serenitas/CorpCDOs/logs/selenium_scotia.log",
)
+ yield driver
+ driver.quit()
def download_scotia_report(workdate):
- scotia_login = {"selene-ops@lmcg.com": "oeujG*UF!53o"}
- for username, password in scotia_login.items():
- REPORT_DIR = DAILY_DIR / "Selene" / "Scotia_reports"
- try:
- fname = next(
- REPORT_DIR.glob(
- f"IsoSelene_{prev_business_day(workdate):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1"
- )
+ username, password = ("selene-ops@lmcg.com", "oeujG*UF!53o")
+ REPORT_DIR = DAILY_DIR / "Selene" / "Scotia_reports"
+ try:
+ fname = next(
+ REPORT_DIR.glob(
+ f"IsoSelene_{prev_business_day(workdate):%d-%b-%Y}_*_xlsx.JOAAPKO3.JOAAPKO1"
)
- logger.info(f"{fname} already exists in {REPORT_DIR}")
- except StopIteration: # File doesn't exist, let's get it"
- fname = download_report(username, password, REPORT_DIR, workdate)
- logger.info(f"Downloaded Scotia Report for {workdate}: {fname}")
+ )
+ logger.info(f"{fname} already exists in {REPORT_DIR}")
+ except StopIteration: # File doesn't exist, let's get it"
+ fname = download_report(username, password, REPORT_DIR, workdate)
+ logger.info(f"Downloaded Scotia Report for {workdate}: {fname}")