-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslud.py
More file actions
76 lines (63 loc) · 2.66 KB
/
slud.py
File metadata and controls
76 lines (63 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import schedule
import time
import telebot
import os
from dotenv import load_dotenv
import logging
from telebot import types
from schedule_forms import get_schedule, wb_name
from utils import add_space_after_nechet_ned
from slud_download import download_file
logging.basicConfig(level=logging.INFO)
load_dotenv()
TOKEN = os.getenv('TOKEN')
if not TOKEN:
raise ValueError("Токен отсутствует в переменных окружения")
bot = telebot.TeleBot(TOKEN)
download_file()
raspis = wb_name()
schedule_name = None
@bot.message_handler(commands=['start'])
def handle_start(message):
markup = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
days = ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"]
buttons = [types.KeyboardButton(day) for day in days]
markup.add(*buttons)
bot.reply_to(message, "Выберите день недели:", reply_markup=markup)
@bot.message_handler(commands=['slud'])
def handle_slud(message):
markup = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
buttons = [types.KeyboardButton(name) for name in raspis]
markup.add(*buttons)
markup.add("/start")
bot.reply_to(message, "Выберите расписание:", reply_markup=markup)
@bot.message_handler(func=lambda message: message.text in ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"])
def handle_day(message):
global schedule_name
day_name = message.text
if schedule_name:
try:
formatted_schedule_name = add_space_after_nechet_ned(schedule_name)
schedule_data = get_schedule(day_name, formatted_schedule_name)
except KeyError:
schedule_data = "Расписание не найдено"
else:
schedule_data = "Расписание не выбрано /slud"
bot.reply_to(message, schedule_data)
@bot.message_handler(func=lambda message: message.text in raspis)
def handle_schedule(message):
global schedule_name
schedule_name = message.text
bot.reply_to(message, f"Расписание для {schedule_name}")
bot.polling(none_stop=True)
@bot.message_handler(commands=['download'])
def handle_download(message):
try:
download_file()
bot.reply_to(message, "Файл успешно скачан.")
except Exception as e:
bot.reply_to(message, f"Ошибка при скачивании файла: {e}")
schedule.every(2).hours.do(download_file)
while True:
schedule.run_pending()
time.sleep(1)