Skip to content

Instantly share code, notes, and snippets.

@garronej
Last active June 5, 2020 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garronej/56a592a12816c44eaecb0c3cd2a657fd to your computer and use it in GitHub Desktop.
Save garronej/56a592a12816c44eaecb0c3cd2a657fd to your computer and use it in GitHub Desktop.
A script that watches when visa registration are open. Set up for www.herault.gouv.fr/booking but can be adapted.
/*
* Prerequisite:
* You will need a supported Huawei 3G dongle:
* https://github.com/bg111/asterisk-chan-dongle/wiki/Requirements-and-Limitations
*
* You also have to install chan-dongle-extended.
* https://garronej.github.io/chan-dongle-extended-pages/
* This tool of mine enable to send SMS via a CLI.
*
* You then need to run this script on something like a raspberry pi
* with a connected 3G dongle.
* Run it with:
*
* $ screen -S visa_watch
* $ wget https://gist.github.com/garronej/56a592a12816c44eaecb0c3cd2a657fd/raw/109ad0a04a9b22f0d90dced0b4f99917b3c4342f/visa_booking_watcher.ts
* $ sudo npm install -g node-fetch scripting-tools typescript ts-node #Or install locally in a package.json
* $ ts-node visa_booking_watcher.ts
*
* After that you can press <Crl-a><d> you can relax you will receive a SMS when the website will be available
* for booking.
*
* PS: Don't forget to replace the phone number and to adapt the script when relevant.
*
*/
import fetch from "node-fetch";
import * as st from "scripting-tools";
const url = "http://www.herault.gouv.fr/booking/create/15262";
//Who to notify when the site is available
const phoneNumbers = [
"0636786385",
"0685683832"
];
console.log({ url });
//Mimic a browser, it could bypass basic anti spam protection mesures.
const headers: { [key: string]: string; } = {
"Cache-Control": "max-age=0",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"
};
(async function main() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 20000));
const fetchResp = await fetch(url, { headers })
.catch((e: Error) => e)
;
if (fetchResp instanceof Error) {
console.warn(fetchResp.message);
continue;
}
const { status } = fetchResp;
console.log(new Date(), { status });
if (status === 502) {
continue;
}
const text = await fetchResp.text()
.catch((e: Error) => e)
;
if (text instanceof Error) {
console.warn(text.message);
continue;
}
if (text.match(/Cette page n'est pas disponible/i)) {
console.log(new Date(), "The page did load but the site is not open for booking");
continue;
}
console.log(new Date(), "The page is ready!");
break;
}
for (const phoneNumber of phoneNumbers) {
try {
await st.exec(
[
`dongle send --imei 861586002697296`,
`--number ${phoneNumber} --text "Wake up! ${url} is up"`
].join(" ")
);
console.log(`SMS sent to ${phoneNumber}`);
} catch (error) {
console.warn(new Date(), error.message);
}
}
await new Promise(resolve => setTimeout(resolve, 240000));
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment