forked from maephisto/buergerbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (63 loc) · 2.77 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
'use strict';
// includes
const open = require('open');
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
const { setIntervalAsync } = require('set-interval-async/dynamic');
const beep = require('beepbeep');
// config of request url params > [note] adapt to your needs
const policeClearanceCertificateId = 120926; // 'Polizeiliches Führungszeugnis'
const registrationOfAccomodation = 120686; // 'Anmeldung einer Wohnung'
const motionOfIdentityCard = 120686; // 'Personalausweis beantragen'
const motionOfPassport = 120686; // 'Reisepass beantragen'
const serviceId = motionOfIdentityCard; // [note] assign the service id here
const baseUrl = 'https://service.berlin.de';
const path = '/terminvereinbarung/termin/tag.php';
const providerList = [122210, 122217,122219,122227,122231,122238,122243,122252,122260,122262,122254,122271,122273,
122277,122280,122282,122284,122291,122285,122286,122296,327262,325657,150230,122301,122297,122294,122312,122314,
122304,122311,122309,317869,324434,122281,122279,122276,122274,122267,122246,122251,122257,122208,122226];
const urlParams = [
'termin=1',
`anliegen[]=${serviceId}`,
`dienstleisterlist=${providerList.join()}`,
`herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F${serviceId}%2F`
];
const checkForAvailableAppointment = async () => {
console.log('> checking for appointments...');
// the url to be crawled > [note] adapt to your needs
const url = `${baseUrl}${path}?${urlParams.join('&')}`;
// get html data of the page
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const html = await page.content();
await browser.close();
// parse html to jQuery-like object using cheerio
const $ = cheerio.load(html);
// parse cells for available days from table
const $availableTerminList = $('.calendar-month-table:first-child td.buchbar a');
// log and alert when availability given
if ($availableTerminList.length > 0) {
console.info('OPEN BOOKINGS!! Go, go, gooooooo!!!!');
// print dates
$availableTerminList.each(async _ => {
// log details
const day = $(this).text();
const month = $(this).parentsUntil('th.month').text();
console.info('...AVAILABLE ON %s %s', day, month);
// get url and open in browser
const pathOfBooking = $(this).attr('href');
const linkOfBooking = new URL(pathOfBooking, baseUrl).toString();
await open(linkOfBooking);
});
// play sound
beep(10, 1500);
} else {
console.info('> No available appointments found')
}
};
console.log('~> 🐒 Starting script');
checkForAvailableAppointment();
// repeat every 30 seconds
setIntervalAsync(checkForAvailableAppointment, 30000);
// https://service.berlin.de/terminvereinbarung/termin/time/1663624800/