def schedule_sender(): bot = telebot.TeleBot(bot_token) db_path = "Bot.db" sql_con = sqlite3.connect(db_path) cursor = sql_con.cursor() cursor.execute("""SELECT id FROM user_data WHERE sending = 1""") data = cursor.fetchall() cursor.close() sql_con.close() tomorrow_moscow_datetime = datetime.today() + timedelta(days=1, hours=3) tomorrow_moscow_date = tomorrow_moscow_datetime.date() for user_data in data: user_id = user_data[0] json_day = get_json_day_data(user_id, tomorrow_moscow_date) full_place = is_full_place(user_id, db_path=db_path) answer = create_schedule_answer(json_day, full_place, user_id, db_path=db_path) if "Выходной" in answer: continue print(user_id, answer) try: answer = "Расписание на завтра:\n\n" + answer send_long_message(bot, answer, user_id) except Exception as err: print(err) continue
def week_day_schedule_handler(call_back): bot_msg = bot.edit_message_text( text="{0}\U00002026".format(choice(loading_text["schedule"])), chat_id=call_back.message.chat.id, message_id=call_back.message.message_id ) is_next_week = False iso_day_date = list((datetime.today() + server_timedelta).isocalendar()) if iso_day_date[2] == 7: iso_day_date[1] += 1 if call_back.data == "Следующее": iso_day_date[1] += 1 is_next_week = True iso_day_date[2] = week_day_number[ week_day_titles[call_back.message.text.split(": ")[-1]]] day_date = func.date_from_iso(iso_day_date) json_day = func.get_json_day_data(call_back.message.chat.id, day_date, next_week=is_next_week) full_place = func.is_full_place(call_back.message.chat.id) answer = func.create_schedule_answer(json_day, full_place, call_back.message.chat.id) try: bot.edit_message_text(text=answer, chat_id=call_back.message.chat.id, message_id=bot_msg.message_id, parse_mode="HTML") except telebot.apihelper.ApiException: func.send_long_message(bot, answer, call_back.message.chat.id)
def schedule_sender(): bot = telebot.TeleBot(release_token) db_path = "spbu4u/Bot_db" sql_con = sqlite3.connect(db_path) cursor = sql_con.cursor() cursor.execute("""SELECT user_data.id, groups_data.json_week_data FROM user_data JOIN groups_data ON (user_data.group_id = groups_data.id AND groups_data.alias = user_data.alias AND sending = 1)""") data = cursor.fetchall() cursor.close() sql_con.close() tomorrow_moscow_datetime = datetime.today() + timedelta(days=1, hours=3) tomorrow_moscow_date = tomorrow_moscow_datetime.date() for user_data in data: user_id, json_week = user_data[0], json.loads(user_data[1]) json_day = get_json_day_data(user_id, tomorrow_moscow_date, json_week) full_place = is_full_place(user_id, db_path=db_path) answer = create_schedule_answer(json_day, full_place, user_id, db_path=db_path) if "Выходной" in answer: continue print(user_id, answer) try: answer = "Расписание на завтра:\n\n" + answer send_long_message(bot, answer, user_id) except Exception as err: print(err) continue
def today_schedule_handler(message): bot.send_chat_action(message.chat.id, "typing") today_moscow_datetime = datetime.today() + server_timedelta today_moscow_date = today_moscow_datetime.date() json_day = func.get_json_day_data(message.chat.id, today_moscow_date) full_place = func.is_full_place(message.chat.id) answer = func.create_schedule_answer(json_day, full_place, message.chat.id) func.send_long_message(bot, answer, message.chat.id)
def schedule_for_day(message): bot.send_chat_action(message.chat.id, "typing") day = func.text_to_date(message.text.lower()) json_week = func.get_json_week_data(message.chat.id, for_day=day) json_day = func.get_json_day_data(message.chat.id, day_date=day, json_week_data=json_week) full_place = func.is_full_place(message.chat.id) answer = func.create_schedule_answer(json_day, full_place, user_id=message.chat.id, personal=True) func.send_long_message(bot, answer, message.chat.id)
def schedule_for_weekday(message): bot.send_chat_action(message.chat.id, "typing") message.text = message.text.title() if message.text in week_day_titles.values(): week_day = message.text else: week_day = week_day_titles[message.text] iso_day_date = list((datetime.today() + server_timedelta).isocalendar()) if iso_day_date[2] == 7: iso_day_date[1] += 1 iso_day_date[2] = week_day_number[week_day] day_date = func.date_from_iso(iso_day_date) json_day = func.get_json_day_data(message.chat.id, day_date) full_place = func.is_full_place(message.chat.id) answer = func.create_schedule_answer(json_day, full_place, message.chat.id) func.send_long_message(bot, answer, message.chat.id)
def all_week_schedule_handler(call_back): user_id = call_back.message.chat.id bot_msg = bot.edit_message_text( text="{0}\U00002026".format(choice(loading_text["schedule"])), chat_id=call_back.message.chat.id, message_id=call_back.message.message_id ) if call_back.data == "Текущее": json_week = func.get_json_week_data(user_id) else: json_week = func.get_json_week_data(user_id, next_week=True) inline_answer = json_week["WeekDisplayText"] bot.answer_callback_query(call_back.id, inline_answer, cache_time=1) is_smth_send = False if len(json_week["Days"]): for day in json_week["Days"]: full_place = func.is_full_place(call_back.message.chat.id) answer = func.create_schedule_answer(day, full_place, call_back.message.chat.id) if "Выходной" in answer: continue if json_week["Days"].index(day) == 0 or not is_smth_send: try: bot.edit_message_text(text=answer, chat_id=user_id, message_id=bot_msg.message_id, parse_mode="HTML") except telebot.apihelper.ApiException: func.send_long_message(bot, answer, user_id) else: func.send_long_message(bot, answer, user_id) is_smth_send = True if not is_smth_send or not len(json_week["Days"]): answer = "{0} Выходная неделя".format(emoji["sleep"]) bot.edit_message_text(text=answer, chat_id=user_id, message_id=bot_msg.message_id)