Skip to content

Instantly share code, notes, and snippets.

@magegu
Created June 24, 2019 12:55
Show Gist options
  • Save magegu/f715897f23625f004d50f37a0d87748d to your computer and use it in GitHub Desktop.
Save magegu/f715897f23625f004d50f37a0d87748d to your computer and use it in GitHub Desktop.
Bürgerbot 2.0
const puppeteer = require("puppeteer");
const notifier = require("node-notifier");
const opn = require("opn");
const url =
"https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&dienstleister=327427&anliegen[]=318998&herkunft=1";
const pollIntervalSeconds = 30;
const extract = async page => {
const nichtBuchbar = await page.$x("//td[@class='nichtbuchbar']");
const unklar = await page.$x("//td[@class='']");
const buchbar = await page.$x("//td[@class='buchbar']");
console.log(new Date(), {
nichtBuchbar: nichtBuchbar.length,
unklar: unklar.length,
buchbar: buchbar.length
});
if (buchbar.length > 0) {
notifier.notify(
{
title: "Terminbuchung",
message: "Möglicherweise Termin buchbar!"
},
function(error, response, metadata) {
opn(url);
}
);
}
};
const requestAmt = async () => {
const browser = await puppeteer.launch({
defaultViewport: null
});
const page = await browser.newPage();
await page.goto(url);
await extract(page);
await page.click(".next");
await extract(page);
await browser.close();
};
setInterval(async () => {
await requestAmt().catch(e => {
console.error(e);
});
}, 1000 * pollIntervalSeconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment