- Бот реагирует на команду /start;
- Далее необходимо отправить ссылку на Ваш запрос в Яндекс.Путешествия (вкладка "Авиабилеты") и отправить ссылку на эту страницу боту;
- Затем бот попросить Вас ввести номер билета (сверху вниз). Если отображается всего один билет, введите "1";
- Бот будет уведомлять Вас о том, что цена изменилась;
- Чтобы остановить работу бота, введите команду /stop;
- Если что-то непонятно, введите /help.
Представляет собой 2 функции:
get_price()
- парсер, реализованный с использованием webdriver. Он дожидается, пока все объекты с классомprice
загрузятся на странице и возвращает список из этих объектов. Объекты в списке имеют типint
.main
- здесь содержится сравнение цен. Бот отправляет сообщение только при условии, что цена меняется. Номер билета передаётся из шага 3 в "Использование" (с технической точки зрения это функцияclarify_the_ticket()
).
Реагирует на команды:
/start
- начало работы с ботом. Сбрасывает значениеpause
наFalse
, поэтому это необходимо прописывать каждый раз, начиная работать с ботом;/stop
- завершить работу с ботом. Изменяет значениеpause
наTrue
, чем останавливает все потоки, идущие отmain()
./help
- помощь После введения команды/start
он ожидает получить ссылку. Валидация ссылки реализована черезmessage.text[8:21] == "travel.yandex"
(да, я не очень заморочился). В противном случае, бот выводит информацию о том, что пользователю нужно обратиться к/help
.
Затем бот просит уточнить номер билета у пользователя. Номер билета считается сверху вниз, то есть первый билет = 1, второй билет = 2 и тд. В противном случае, придётся заново отправлять ссылку боту.
- Создайте файл
config.py
; - Создайте переменную
token
и в качестве значения используйте строку, содержащую API Token, полученный от Bot Father; - Создайте переменную
delay
и в качестве значения используйте натуральное число. Задержка указывается в секундах. По умолчанию это значение составляет 10 минут.
Не стоит отправлять боту одну и ту же ссылку несколько раз. Библиотека threading
создаёт то количество запросов, сколько раз была отправлена ссылка. Возможна ситуация, когда бот просто ляжет, дав слишком большую нагрузку на сервер своими запросами (или парсер перестанет передавать значения)
- The bot responds to the /start command;
- Next, you need to send a link to your request to Yandex.Travel (the "Flights" tab) and send a link to this page to the bot;
- Then the bot will ask you to enter the ticket number (from top to bottom). If only one ticket is displayed, enter "1";
- The bot will notify you that the price has changed;
- To stop the bot, enter the /stop command;
- If something is not clear, enter /help.
Represents 2 functions:
get_price()
is a parser implemented using webdriver. It waits for all objects with theprice
class to load on the page and returns a list of these objects. The objects in the list are of typeint
.main
- contains a price comparison. The bot sends a message only if the price changes. The ticket number is passed from step 3 in "Usage" (technically, this is the functionclarify_the_ticket()
).
Responds to commands:
/start
- start working with the bot. Resets thepause
value toFalse
, so this must be specified every time you start working with the bot;/stop
- stop working with the bot. Changes the value ofpause
toTrue
, which stops all threads coming frommain()
;/help
- help. After entering the/start
command, it expects to get a link. Link validation is implemented viamessage.text[8:21] == " travel.yandex"
(yes, I didn't really bother). Otherwise, the bot outputs information that the user needs to access/help
.
The bot then asks the user to specify the ticket number. The ticket number is counted from top to bottom, i.e. first ticket = 1, second ticket = 2, etc. Otherwise, you will have to re-send the link to the bot.
- Create a file
config.py
; - Create the
token
variable and use the string containing the API Token received from Bot Father as the value; - Create the
delay
variable and use a natural number as the value. The delay is specified in seconds. By default, this value is 600 (10 minutes).
Do not send the same link to the bot several times. The threading
library creates the number of requests that equals the number of times the link was sent by the user. There may be a situation when the bot simply lies down, giving too much load on the server with its' requests (or the parser stops transmitting values)