Last active
January 7, 2019 10:32
-
-
Save Hydrock/e80ba3ee5c06b200e9ba9e065bd7c59f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| const targetLink = 'http://nekrasovka.ru/afisha/19-01-2019/1224'; | |
| let index; | |
| function setMonitor () { | |
| // Тут делаем запрос и формируем тело ответа | |
| http.get(targetLink, (res) => { | |
| // Так как тело ответа прилетает порциями, | |
| // кладем все в массив и затем формируем строку ответа | |
| let body = []; | |
| res.on('data', function (chunk) { | |
| body.push(chunk); | |
| }); | |
| // Проверяем наличение строки в ответе | |
| res.on('end', () => { | |
| body = Buffer.concat(body).toString(); | |
| index = body.indexOf('Регистрация на мероприятие завершена'); | |
| }); | |
| }) | |
| // Если в теле ответа есть строка 'Регистрация на мероприятие завершена', | |
| // запускаем мониторинг еще раз, иначе пишем что пора регистрироваться! | |
| if (index !== -1) { | |
| setTimeout(() => { | |
| console.log('Пока ничего нет...'); | |
| setMonitor(); | |
| }, 10000); | |
| } else { | |
| console.log('Ура! Доступно! Скорее регайся!'); | |
| } | |
| } | |
| setMonitor(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment