Skip to content

Commit

Permalink
Merge pull request #13 from azuki774/develop-refresh-button
Browse files Browse the repository at this point in the history
money-forward の金融機関等の[更新]を押す
  • Loading branch information
azuki774 authored Sep 2, 2023
2 parents f066be5 + 5680939 commit 9011545
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deployment/money-forward.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[email protected]
pass=xxxxxx
urls="https://moneyforward.com/bs/xxxxx,https://moneyforward.com/accounts/yyyyy"
urls="https://moneyforward.com/bs/xxxxx,https://moneyforward.com/accounts/yyyyy,https://moneyforward.com/cf" # 取得するページを , 区切りで記載
refresh_xpaths="xxxxxxxx,xxxxxxxx" # https://moneyforward.com に表示される金融機関等の[更新]ボタンのXPATHを , 区切りで記載
16 changes: 16 additions & 0 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 @@ -37,6 +40,7 @@ def main():
lg.info("Get driver")
driver = get_driver()

# login
try:
html = money.login(driver)
except Exception as e:
Expand All @@ -46,6 +50,18 @@ def main():

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

# Refresh Button
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:
try:
html = money.get_from_url(driver, url)
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 9011545

Please sign in to comment.