ken_nogi/NodeJS/JigyoKeikakuUpdate/JigyoKeikakuUpdate.js
Kenichiro NOGI 7b357fa2cf 2025-11-08
2025-11-08 10:26:52 +09:00

87 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { Builder, By, until } = require('selenium-webdriver');
/**
* 指定したURLをChromeで開き、ログインID・パスワードを入力してLoginボタンをクリックし、
* その後id="UpdateCommand"のボタンをクリックして10秒待機する
* @param {string} url 開くWEBサイトのURL
* @param {string} loginId ログインID
* @param {string} password パスワード
*/
const baseUrl = 'https://nextoffice.next-hd.co.jp/pleasanter';
//const baseUrl = 'https://neo999.next-hd.net/pleasanter';
async function openAndClickUpdateCommand(url, loginId, password) {
let driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get(url);
// ログインID・パスワード入力
await driver.wait(until.elementLocated(By.id('Users_LoginId')), 10000);
await driver.findElement(By.id('Users_LoginId')).sendKeys(loginId);
await driver.wait(until.elementLocated(By.id('Users_Password')), 10000);
await driver.findElement(By.id('Users_Password')).sendKeys(password);
// Loginボタンをクリック
await driver.wait(until.elementLocated(By.id('Login')), 10000);
await driver.findElement(By.id('Login')).click();
await driver.sleep(5000);
// id="UpdateCommand"のボタンが表示されるまで待機最大10秒
const button = await driver.wait(
until.elementLocated(By.id('UpdateCommand')),
10000
);
await button.click();
await driver.sleep(10000);
} finally {
await driver.quit();
}
}
async function getPleasanterData() {
const tableId = '214737'; // サブテーブルのIDを指定
const apiKey = '6504c8a807677a3a576e10327f3c19876c55736ee45d4a845796b9e7f5e087bfd4bd0d8184863da8cf1733ca635111432ab334aea59102b06a96ee6d2c05190d';
const pleasanterUrl = baseUrl + '/api/items/' + tableId + '/get'
// ここにPleasanterからデータを取得するためのコードを追加します
const jsonBody = {
'ApiVersion': 1.1,
'ApiKey': apiKey,
'View': {
'ColumnSorterHash': {
'ClassB': 'asc'
},
'ColumnFilterHash': {
'ClassZ': '["2025"]'
},
}
}
const pleasanterRes = await fetch(pleasanterUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(jsonBody)
});
const resData = await pleasanterRes.json();
//console.log(resData);
for (const item of resData.Response.Data) {
let resultId = item.ResultId.toString();
const url = baseUrl + '/items/' + resultId + '/edit';
const loginId = 'SystemUser'; // 実際のログインIDに変更
const password = "pfS+Zx&\\'hFaz0w|X&V1"; // 実際のパスワードに変更
await openAndClickUpdateCommand(url, loginId, password)
.then(() => console.log('完了'))
.catch(err => console.error('エラー:', err));
}
}
function main() {
getPleasanterData();
}
//処理開始
main();