master
Ernest Litvinenko 2024-03-05 15:31:21 +03:00
parent 993cd8b305
commit 069ce87453
2 changed files with 10 additions and 11 deletions

14
main.py
View File

@ -252,14 +252,12 @@ PARSER_ALIVE = True
def parse_runner():
while True:
with Parser() as parser:
parser.login()
while True:
if PARSER_ALIVE:
while PARSER_ALIVE:
parser.search()
time.sleep(60)
else:
time.sleep(1)
parser_thread = threading.Thread(target=parse_runner, daemon=True)
@ -283,22 +281,22 @@ async def message_handler(message: Message):
await message.answer("Вы не зарегистрированы, обратитесь к администратору")
return
markup = ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text="Запустить Бот")]])
markup_start = ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text="Запустить Бот")]])
markup_shutdown = ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text="Остановить Бот")]])
if message.text == "Запустить Бот":
PARSER_ALIVE = True
for chat_id in s.get_users():
await bot.send_message(chat_id,
f"Пользователь {message.from_user.full_name} запускает бот",
reply_markup=markup)
reply_markup=markup_shutdown)
parser_thread.start()
return
if message.text == "Остановить Бот":
for chat_id in s.get_users():
await bot.send_message(chat_id,
f"Пользователь {message.from_user.full_name} остановил бот",
reply_markup=markup)
reply_markup=markup_start)
PARSER_ALIVE = False
await message.answer("Бот остановлен", reply_markup=markup)
return
await message.answer("Неизвестная команда")

View File

@ -1,5 +1,6 @@
import json
import loguru
import requests
from loguru import logger
from storage import Storage
@ -22,7 +23,7 @@ def _log(message):
"chat_id": int(chat_id),
"disable_notification": True,
"text": icon + message,
"reply_markup": json.dumps({"keyboard": [[{"text": "Остановить Бот"}]]})
# "reply_markup": json.dumps({"keyboard": [[{"text": "Остановить Бот"}]]})
})
if r.status_code != 200:
print(r.json())