-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
111 lines (86 loc) · 2.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const { chromium } = require('playwright');
const notifier = require('node-notifier');
const NL_PERMIT_SCHEDULE_URL = 'https://oap.ind.nl/oap/en/#/doc';
const DESK_VALUES = {
AMSTERDAM: '1: Object',
DEN_HAAG: '2: Object',
ZWOLLE: '3: Object',
DEN_BOSCH: '4: Object'
};
const TIME_OPTIONS = {
// just use first available
FIRST: '1: Object'
};
const CHECKING_TIMEOUT = 3000;
const timeFormatter = new Intl.DateTimeFormat(
'en-us',
{ hour: 'numeric', minute: 'numeric', second: 'numeric' }
);
const log = message => {
console.log(`[${timeFormatter.format(new Date())}]: ${message}`);
};
const notify =() =>
notifier.notify({
title: 'NL Permit appointment available!',
message: 'Could you please to go to the bot Chromium instance and the filling form',
sound: true,
wait: true
});
const selectDesk = async (page, desk) => {
await page.selectOption('#desk', desk);
}
const incrementMonth = async page => {
await page.locator('available-date-picker button.pull-right').click();
};
const tryToFindAvailableDate = async page => {
try {
// select date
const locator = page.locator(
'available-date-picker tbody tr:nth-child(-n+3) button.btn-sm.available'
).first();
await locator.waitFor({ timeout: 500 });
await locator.click();
// select time
await page.selectOption('#timeSlot', TIME_OPTIONS.FIRST);
// start filling
await page.locator(
'button.pull-right[type="submit"]:has-text("To details")'
).click();
notify();
} catch (e) {
log('Not available dates');
setTimeout(() => check(page), CHECKING_TIMEOUT);
}
}
/**
* @param {import('playwright').Page} page
*/
const check = async page => {
await page.goto(NL_PERMIT_SCHEDULE_URL);
log('Page reloaded');
await selectDesk(page, DESK_VALUES.AMSTERDAM);
// await incrementMonth(page);
await incrementMonth(page);
await tryToFindAvailableDate(page);
};
const runChecker = (page) => new Promise(() => {
check(page);
});
const run = async () => {
console.log(
`
!!! Be ready to filling the appointment form !!!
Could you please prepare:
- your email
- your phone (NL prefer)
- V-number (form IND approval letter)
- First name (which you are using in documents)
- Last name (which you are using in documents)
`
);
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await runChecker(page);
await browser.close();
};
run();