Skip to content

Commit

Permalink
add update button func
Browse files Browse the repository at this point in the history
  • Loading branch information
azuki774 committed Sep 2, 2023
1 parent 663e16c commit 5680939
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/money-forward/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
Expand All @@ -10,6 +11,8 @@
import logging
from pythonjsonlogger import jsonlogger

ROOTPAGE_URL="https://moneyforward.com"

lg = logging.getLogger(__name__)
lg.setLevel(logging.DEBUG)
h = logging.StreamHandler()
Expand Down Expand Up @@ -47,9 +50,16 @@ def main():

urls = os.getenv("urls").split(",")


# Refresh Button
# TODO
money.move_page(driver, ROOTPAGE_URL)
refresh_xpaths = os.getenv("refresh_xpaths").split(",")
for xpath in refresh_xpaths:
try:
money.press_from_xpath(driver, xpath)
lg.info("press update button: %s", xpath)
time.sleep(30) # 反映されるように30sec待っておく
except Exception as e:
lg.warn('failed to press update button: %s', e)

# download HTML
for url in urls:
Expand Down
19 changes: 19 additions & 0 deletions src/money-forward/money.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ def get_from_url_cf_lastmonth(driver):
return


def move_page(driver, url):
wait = WebDriverWait(driver=driver, timeout=30)
lg.info("move page url: " + url)
driver.get(url)
return

def press_from_xpath(driver, xpath):
"""
指定したxpathのリンクを押す
ページはすでに遷移済にしておくこと
"""
xpath_link = driver.find_element(
by=By.XPATH,
value=xpath,
)
xpath_link.click()
return


def write_html(html, url):
today = dt.date.today() # 出力:datetime.date(2020, 3, 22)
yyyymmdd = "{0:%Y%m%d}".format(today) # 20200322
Expand Down

0 comments on commit 5680939

Please sign in to comment.