title | tags | parameters | reference | ||||||
---|---|---|---|---|---|---|---|---|---|
マネーフォワードの資産、負債をGoogle Sperad Sheetに記録します |
|
|
Last active
June 3, 2023 13:22
-
-
Save freddiefujiwara/ce84aa2b8e0f4e9e28f47294ce4c1e09 to your computer and use it in GitHub Desktop.
dogbot-moneyforward-spreadsheet.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
I | |
} = inject(); | |
module.exports = { | |
async run() { | |
const sheets = { | |
"liability": { | |
"xpath": '//*[@id="bs-liability"]/section/div/section/table/tbody/tr[1]/td[1]', | |
"list": [1, 2] | |
}, | |
"portfolio": { | |
"xpath": '//*[@id="bs-portfolio"]/div[1]/div/div[1]/section/div[2]/div/section/table/tbody/tr[1]/td[1]', | |
"list": [1, 2, 3, 4, 5, 6] | |
} | |
} | |
I.say("Login"); | |
I.amOnPage('https://moneyforward.com/bs/liability'); | |
I.click('img[alt="email"]'); | |
I.fillField('mfid_user[email]', process.env.MF_EMAIL); | |
I.click('input[type="submit"]'); | |
I.fillField('mfid_user[password]', process.env.MF_PASSWORD); | |
I.click('input[type="submit"]'); | |
I.say("Grabs"); | |
for await (sheet of Object.keys(sheets)) { | |
for await (i of sheets[sheet].list) { | |
I.amOnPage(`https://moneyforward.com/bs/${sheet}`); | |
const contents = (await I.grabTextFrom(sheets[sheet].xpath.replace("tr[1]", `tr[${i}]`))).replace(/[,円]/g, ''); | |
I.amOnPage(`${process.env.APIURL}?x=2&y=${1+i}&contents=${contents}&sheet=${sheet}`); | |
} | |
}; | |
const xpath = '//*[@id="portfolio_det_mf"]/table/tbody/tr[V]/td[H]'; | |
let v = 1; | |
let finish = false; | |
I.amOnPage(`https://moneyforward.com/bs/portfolio`); | |
while (!finish) { | |
if (0 === (await I.grabNumberOfVisibleElements(xpath.replace("tr[V]", `tr[${v}]`).replace("td[H]", `td[1]`)))) { | |
finish = true; | |
continue; | |
} | |
for await (h of [1, 2, 3, 4, 5, 6, 7, 8]) { | |
const contents = encodeURI((await I.grabTextFrom(xpath.replace("tr[V]", `tr[${v}]`).replace("td[H]", `td[${h}]`))).replace(/[,&円]/g, '')); | |
I.amOnPage(`${process.env.APIURL}?x=${h}&y=${1+v}&contents=${contents}&sheet=investment%20trusts`); | |
I.amOnPage(`https://moneyforward.com/bs/portfolio`); | |
} | |
v++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment