diff --git a/.gitignore b/.gitignore
index 34ad6fc..73243d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,8 @@ users.json
schedule.json
json/students.json
json/schedule_2sem.json
+test_json
+json_remake
+script.py
nohup.out
config.yaml
diff --git a/for_json.py b/for_json.py
index 1c23248..e8fea00 100644
--- a/for_json.py
+++ b/for_json.py
@@ -58,50 +58,20 @@ def change_user_param(id, key, value):
with open(path_users, "w", encoding="utf-8") as json_file:
json.dump(data, json_file, ensure_ascii=False, indent=4)
create_schedule_tasks()
- bot.send_admin_message(
- "Изменения:\
- \nuser: @{}\
- \nid: {}\
- \nkey: {}\
- \nvalue: {}".format(
- data[id]["username"], id, key, value
- )
- )
+
+ # bot.send_admin_message(
+ # "Изменения:\
+ # \nuser: @{}\
+ # \nid: {}\
+ # \nkey: {}\
+ # \nvalue: {}".format(
+ # data[id]["username"], id, key, value
+ # )
+ # )
+
return
-def parse_lesson_tmp(time, lesson):
- text = ""
- start, end = time.split("-")
-
- if len(lesson["infos"].split("|")) == 2:
- teacher = lesson["infos"].split("|")[0]
- room = lesson["infos"].split("|")[1]
- text = "{}-{} | {}\
- \n{}\
- \n{}".format(
- start, end, room, lesson["name"], teacher
- )
- elif len(lesson["infos"].split("|")) == 4:
- infos = lesson["infos"].split("|")
- text = "{}-{}\
- \n{}\
- \n({}) {}\
- \n({}) {}".format(
- start, end, lesson["name"], infos[1], infos[0], infos[3], infos[2]
- )
- elif len(lesson["infos"].split("|")) == 1:
- text = "{}-{}\
- \n{}".format(
- start, end, lesson["name"]
- )
- else:
- print("что-то не так")
- print(lesson["name"])
-
- return text
-
-
def parse_lesson(lesson: dict[str, str]) -> str:
text = ""
start, end = lesson["begin"], lesson["end"]
@@ -128,6 +98,8 @@ def parse_lesson(lesson: dict[str, str]) -> str:
)
for tr in lesson["teacher.room"]:
+ if not tr["t"] and not tr["r"]:
+ continue
text += "\n({}) {}".format(tr["r"], tr["t"])
return text
@@ -140,7 +112,7 @@ def create_schedule_tasks(manual=False):
if not allow_update:
return
- bot.send_admin_message("Произошёл auto-update")
+ # bot.send_admin_message("Произошёл auto-update")
allow_update = True
@@ -184,27 +156,27 @@ def create_schedule_tasks(manual=False):
if day == "mon":
schedule.every().monday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "tue":
schedule.every().tuesday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "wed":
schedule.every().wednesday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "thu":
schedule.every().thursday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "fri":
schedule.every().friday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "sat":
schedule.every().saturday.at(start_task).do(
- bot.send_message, id, text, thread_id, lesson["partity"]
+ bot.send_message, id, text, thread_id, lesson["parity"]
)
return
@@ -311,8 +283,16 @@ def get_schedule(id: str, day: str) -> str:
)
for lesson in schdl_today:
- text += "•" + parse_lesson(lesson) + "\n\n"
+ str_lesson = parse_lesson(lesson)
+ if str_lesson:
+ text += "•" + str_lesson + "\n\n"
except:
return "Расписания твоей группы нет"
return text
+
+
+if __name__ == "__main__":
+ print(groups_in_json())
+
+ pass
diff --git a/json/groups/groups.json b/json/groups/groups.json
index 12ad73b..f77e36a 100644
--- a/json/groups/groups.json
+++ b/json/groups/groups.json
@@ -1,4 +1,26 @@
[
+ "101",
+ "102",
+ "103",
+ "104",
+ "105",
+ "106",
+ "107",
+ "108",
+ "109",
+ "110",
+ "111",
+ "112",
+ "113",
+ "114",
+ "115",
+ "116",
+ "117",
+ "118",
+ "119",
+ "120",
+ "141",
+ "142",
"201",
"202",
"203",
diff --git a/schedules.py b/schedules.py
index 092aa83..a00a8c2 100644
--- a/schedules.py
+++ b/schedules.py
@@ -10,7 +10,7 @@ from admin import admin_command, is_admin, send_admin_message, send_admin_docume
config = yaml.safe_load(open("config.yaml"))
bot = telebot.TeleBot(config["test_token"])
-PARTITY_FIRST = 1
+parity_FIRST = 1
@bot.message_handler(commands=["help", "faq"])
@@ -67,7 +67,7 @@ def test(message):
@admin_command
def restart_bot(message):
send_admin_message("bye")
- os.execv(sys.executable, ["python"] + sys.argv)
+ os.execv(sys.executable, ["python3", "-u"] + sys.argv)
@bot.message_handler(commands=["update"])
@@ -147,7 +147,7 @@ def spam(message):
def spam_msg(message):
if message.text == "stop" or message.text == "стоп" or message.text[0] == "/":
- send_admin_message("Отмена отпраки")
+ send_admin_message("Отмена отправки")
return
send_admin_message("Пришли мне текст для рассылки сообщения этим пользователям")
@@ -159,7 +159,7 @@ def spam_msg(message):
def spam_cnf(message, data):
if message.text == "stop" or message.text == "стоп" or message.text[0] == "/":
- send_admin_message("Отмена отпраки")
+ send_admin_message("Отмена отправки")
return
global text_spam
@@ -197,7 +197,7 @@ def spam_cnf(message, data):
@bot.callback_query_handler(func=lambda call: "spam" in call.data)
def spam_send(call):
if call.data == "spam_no":
- send_admin_message("Отмена отпраки")
+ send_admin_message("Отмена отправки")
return
tmp, data = call.data.split("#")
@@ -314,17 +314,14 @@ def start(message):
send_message(message.chat.id, start_txt)
markup = types.InlineKeyboardMarkup()
- for i in for_json.groups_in_json():
- markup.add(types.InlineKeyboardButton(text=i, callback_data=i))
+ # for i in for_json.groups_in_json():
+ # markup.add(types.InlineKeyboardButton(text=i, callback_data=i))
+ markup.add(types.InlineKeyboardButton(text="1 курс", callback_data="1course"))
+ markup.add(types.InlineKeyboardButton(text="2 курс", callback_data="2course"))
- markup.add(
- types.InlineKeyboardButton(
- text="Моей группы нет в этом списке", callback_data="other"
- )
- )
bot.send_message(
message.chat.id,
- "Пожалуйста, выбери свою группу",
+ "Пожалуйста, выбери свой курс",
parse_mode=ParseMode.HTML,
reply_markup=markup,
)
@@ -333,9 +330,36 @@ def start(message):
@bot.callback_query_handler(
- func=lambda call: call.data in for_json.groups_in_json() or call.data == "other"
+ func=lambda call: call.data in for_json.groups_in_json()
+ or call.data in ["other", "1course", "2course"]
)
def callback_inline(call):
+ if "course" in call.data:
+ course = call.data[0]
+
+ markup = types.InlineKeyboardMarkup()
+ for i in [i for i in for_json.groups_in_json() if i[0] == course]:
+ markup.add(types.InlineKeyboardButton(text=i, callback_data=i))
+
+ markup.add(
+ types.InlineKeyboardButton(
+ text="Моей группы нет в этом списке", callback_data="other"
+ )
+ )
+
+ bot.edit_message_text(
+ text="Пожалуйста, выбери свою группу",
+ chat_id=call.message.chat.id,
+ message_id=call.message.message_id,
+ reply_markup=markup,
+ )
+
+ # bot.edit_message_reply_markup(
+ # call.message.chat.id, call.message.message_id, reply_markup=markup
+ # )
+
+ return
+
infos = [
call.from_user.id,
call.from_user.first_name,
@@ -350,8 +374,7 @@ def callback_inline(call):
bot.edit_message_text(
chat_id=call.message.chat.id,
message_id=call.message.message_id,
- text="Используй команду /request \
- и напиши номер группы, которую хочешь добавить\
+ text="Используй команду /request и напиши номер группы, которую хочешь добавить\
\nПосле создания расписания для твоей группы, я пришлю тебе сообщение",
parse_mode=ParseMode.HTML,
)
@@ -609,7 +632,7 @@ def request(message):
def send_request(message):
if message.text == "stop" or message.text == "стоп" or message.text[0] == "/":
- send_message(message.from_user.id, "Отмена отпраки")
+ send_message(message.from_user.id, "Отмена отправки")
return
infos = [
@@ -658,15 +681,15 @@ def text_message(message):
return
-def send_message(id, text, thread_id="General", partity=None):
+def send_message(id, text, thread_id="General", parity=None):
if thread_id == "General":
thread_id = None
- if partity:
+ if parity:
count_of_weeks = (datetime.now() - datetime(2024, 2, 5)).days // 7
- is_odd = (count_of_weeks + 1) % 2 == PARTITY_FIRST
+ is_odd = (count_of_weeks + 1) % 2 == parity_FIRST
- if is_odd != bool(partity):
+ if is_odd != bool(parity):
return
try:
@@ -691,8 +714,8 @@ def send_message(id, text, thread_id="General", partity=None):
text_error = "Error from user: @{} {}\n{}".format(
for_json.return_infos(id)["username"], id, str(e)
)
- send_admin_message(text_error)
- print(id, e)
+ # send_admin_message(text_error)
+ print(f"--- {text_error} ---")
return