Skip to content

Commit

Permalink
feat: add check-in/check-out param
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergi Romeu committed Sep 17, 2023
1 parent 8a602fb commit 6f30774
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This tool allows you to automatically check-in and check-out on HRLog (MAC only

2. Create a scripts folder under `~/.scripts`

3. Place the `hrlog-auto-...` script under `~/.scripts`. The script accepts 3 params in the following order: email, password, showWindow (this last is for debug purposes only)
3. Place the `hrlog-auto-...` script under `~/.scripts`. The script accepts 4 params in the following order: email(string), password(string), type(string, 'check-in' or 'check-out'), showWindow(boolean/number, this last is for debug purposes only)

4. Modify the `crontab.txt` call to the script to include your credentials by replacing "YOUR_EMAIL" and "YOUR_PASSWORD"

Expand Down
4 changes: 2 additions & 2 deletions crontab.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
05 9 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD
05 17 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD
05 9 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD check-in
05 17 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD check-out
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { chromium } = require('playwright');

(async () => {
const [email, password, showWindow] = process.argv.slice(2)
const [email, password, type, showWindow] = process.argv.slice(2)
// Setup
const browser = await chromium.launch(showWindow ? {headless: false} : {headless: true});
const context = await browser.newContext({permissions: ['geolocation']});
const page = await context.newPage();

// The actual interesting bit
await page.goto('https://app.hrlog.es/admin/login');

Expand All @@ -19,7 +18,8 @@ const { chromium } = require('playwright');

await page.waitForURL('**/secure/dashboard');

await page.locator('#div-fichaje-action').click();
const textToSearch = type === 'check-in' ? 'Entrada trabajo' : 'Salida trabajo';
await page.getByText(textToSearch).click();
await page.waitForResponse((response) => response.url().includes("/secure/ajax-ultimo-fichaje"));

// Teardown
Expand Down
38 changes: 27 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "hrlog-auto",
"version": "2.1.0",
"version": "3.0.0",
"description": "",
"main": "main.js",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"playwright": "1.36.1"
"playwright": "1.38.0"
}
}

0 comments on commit 6f30774

Please sign in to comment.