-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a6438e8
Showing
13 changed files
with
798 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ID='' | ||
PW='' | ||
NOTIFY_URL='' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
caps/*.png |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd `dirname $0`/../ | ||
|
||
yarn syukkin |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd `dirname $0`/../ | ||
|
||
yarn taikin |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "kintai", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"syukkin": "rm -f caps/*.png && node -r dotenv/config -r esbuild-register src/syukkin.ts", | ||
"taikin": "rm -f caps/*.png && node -r dotenv/config -r esbuild-register src/taikin.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/node-fetch": "^3.0.3", | ||
"@types/puppeteer": "^5.4.4", | ||
"dotenv": "^10.0.0", | ||
"esbuild": "^0.13.3", | ||
"esbuild-register": "^3.0.0", | ||
"prettier": "^2.4.1", | ||
"typescript": "^4.4.3" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^3.0.0", | ||
"puppeteer": "^10.4.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import puppeteer from "puppeteer"; | ||
// import fetch from "node-fetch"; | ||
|
||
const fetch = (...args: any[]) => | ||
// @ts-ignore | ||
import("node-fetch").then(({ default: fetch }) => fetch(...args)); | ||
|
||
export async function login(page: puppeteer.Page, id: string, pw: string) { | ||
const _cap = cap(page); | ||
|
||
// ページ表示 | ||
await page.goto("https://s2.kingtime.jp/independent/recorder/personal/"); | ||
await _cap("0-1-login1"); | ||
|
||
// 入力 | ||
await page.type("input#id", id); | ||
await page.type("input#password", pw); | ||
await _cap("0-2-login2"); | ||
|
||
// ログイン | ||
await page.click(".btn-control-message"); | ||
|
||
// TOPページ表示を待つ | ||
await page.waitForSelector("#buttons"); | ||
await _cap("0-3-top1"); | ||
} | ||
|
||
export const cap = | ||
(page: puppeteer.Page) => | ||
async (imageName: string, captureOptions?: puppeteer.ScreenshotOptions) => { | ||
await page.screenshot({ path: `caps/${imageName}.png`, ...captureOptions }); | ||
console.info(`capture! ${imageName}`); | ||
}; | ||
|
||
export const notify = async (text: string, url: string) => { | ||
const body = JSON.stringify({ text }); | ||
const headers = { "Content-Type": "application/json" }; | ||
|
||
const res = await fetch(url, { method: "POST", headers, body }); | ||
if (!res.ok) { | ||
console.warn(res.status.toString()); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import puppeteer from "puppeteer"; | ||
import { login, cap, notify } from "./lib"; | ||
|
||
const { ID, PW, NOTIFY_URL } = process.env; | ||
|
||
console.info("start"); | ||
main() | ||
.then(() => { | ||
console.info("end"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
async function main() { | ||
if (!ID) throw new Error("環境変数ないよ ID"); | ||
if (!PW) throw new Error("環境変数ないよ PW"); | ||
if (!NOTIFY_URL) throw new Error("環境変数ないよ NOTIFY_URL"); | ||
|
||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
const _cap = cap(page); | ||
|
||
try { | ||
// ログインしてトップページの表示待つ | ||
await login(page, ID, PW); | ||
|
||
// 勤怠ボタン | ||
await page.click(".record-clock-in"); | ||
await page.waitForFunction( | ||
'document.querySelector("body").innerText.includes("出勤が完了しました")' | ||
); | ||
await page.waitForTimeout(1000); // wait fade-in animation | ||
await _cap("1-0kintai"); | ||
} catch (err) { | ||
await _cap("99-error"); | ||
throw err; | ||
} | ||
|
||
await browser.close(); | ||
|
||
await notify("しゅっきん", NOTIFY_URL); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import puppeteer from "puppeteer"; | ||
import { login, cap, notify } from "./lib"; | ||
|
||
const { ID, PW, NOTIFY_URL } = process.env; | ||
|
||
console.info("start"); | ||
main() | ||
.then(() => { | ||
console.info("end"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
async function main() { | ||
if (!ID) throw new Error("環境変数ないよ ID"); | ||
if (!PW) throw new Error("環境変数ないよ PW"); | ||
if (!NOTIFY_URL) throw new Error("環境変数ないよ NOTIFY_URL"); | ||
|
||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
const _cap = cap(page); | ||
|
||
try { | ||
// ログインしてトップページの表示待つ | ||
await login(page, ID, PW); | ||
|
||
// 勤怠ボタン | ||
await page.click(".record-clock-out"); | ||
await page.waitForFunction( | ||
'document.querySelector("body").innerText.includes("退勤が完了しました")' | ||
); | ||
await page.waitForTimeout(1000); // wait fade-in animation | ||
await _cap("1-0kintai"); | ||
} catch (err) { | ||
await _cap("99-error"); | ||
throw err; | ||
} | ||
|
||
await browser.close(); | ||
|
||
await notify("たいきん", NOTIFY_URL); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "commonjs", | ||
"strict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true | ||
} | ||
} |
Oops, something went wrong.