Polling with notifications for booking.uz.gov.ua
- Open https://booking.uz.gov.ua in modern browser
- Type search parameters and submit form
- Copy next script and run in browser dev console:
const script = document.createElement("script");
script.type = "module";
script.textContent = `
import {startPolling} from 'https://rawgit.com/bodia-uz/booking-uz-polling/master/index.js'
startPolling();
`;
document.body.appendChild(script);
const stopPolling = startPolling({
pollingIntervalMs: 3 * 60 * 1000,
resultToString: result => JSON.stringify(result),
onResult: (resultStr, result) => console.log(result),
onResultChanged: (resultStr, result) => console.log(result)
});
// run `stopPolling()` to stop polling;
Add chat with @TrainKetsBot and follow instructions.
⚠️ WARN: TrainKetsBot is currently not working, so use manuall about how to create your own bot.
Or create your own bot:
- Register in telegram
- Create new bot using @BotFather command
/newbot
and get<token>
- Write random text to your bot and extract
<chat_id>
fromhttps://api.telegram.org/bot<token>/getUpdates
response:<chat_id>
=response->message->chat->id
- Use
onResultChanged
function to notify via telegram:
const script = document.createElement("script");
script.type = "module";
script.textContent = `
import {startPolling} from 'https://rawgit.com/bodia-uz/booking-uz-polling/master/index.js'
startPolling({
onResultChanged(results) {
fetch('https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat_id>&text=' + encodeURIComponent(results))
}
});
`;
document.body.appendChild(script);
UZ introduced captche, so now we have one more restriction.
Workaround - send notification every time, captcha is shown. It will let you resolve it and continue search polling.
Code:
let wasCaptchaVisible;
function checkCaptcha() {
const isCaptchaVisible = Array.from(
document.querySelectorAll('iframe[title~=reCAPTCHA]'),
).some((frame) => window.getComputedStyle(frame).visibility === 'visible');
if (isCaptchaVisible !== wasCaptchaVisible) {
fetch(
`https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat_id>&text=${
isCaptchaVisible ? 'Captcha is visible' : 'Captcha is hidden'
}`,
);
console.log({ isCaptchaVisible, wasCaptchaVisible });
wasCaptchaVisible = isCaptchaVisible;
}
}
setInterval(checkCaptcha, 30 * 1000);
checkCaptcha();