2023-04-30 00:13:44 +03:00
|
|
|
|
## code ##
|
2023-05-04 19:46:37 +03:00
|
|
|
|
def get_full_schedule():
|
2023-02-25 15:54:16 +02:00
|
|
|
|
# baking defined schedule
|
|
|
|
|
raw_schedule = json.loads( readfile(self.path + "schedule.json") )
|
|
|
|
|
schedule = {}
|
|
|
|
|
for day in range(len(raw_schedule)):
|
|
|
|
|
for i in raw_schedule[day]:
|
|
|
|
|
ts = day*86400 + int(i.split(":")[0])*3600 + int(i.split(":")[1])*60
|
|
|
|
|
new_item = dict(raw_schedule[day][i])
|
|
|
|
|
new_item["source"] = "schedule"
|
|
|
|
|
schedule[ts] = new_item
|
2023-04-27 11:22:25 +03:00
|
|
|
|
|
|
|
|
|
# baking additions (extra lessons)
|
2023-02-25 15:54:16 +02:00
|
|
|
|
raw_additions = json.loads( readfile(self.path + "additions.json") )
|
|
|
|
|
additions = {}
|
|
|
|
|
for day in range(len(raw_additions)):
|
|
|
|
|
for i in raw_additions[day]:
|
|
|
|
|
ts = day*86400 + int(i.split(":")[0])*3600 + int(i.split(":")[1])*60
|
|
|
|
|
new_item = dict(raw_additions[day][i])
|
|
|
|
|
new_item["source"] = "additions"
|
|
|
|
|
schedule[ts] = new_item
|
|
|
|
|
|
2023-04-30 00:13:44 +03:00
|
|
|
|
full_schedule = dict(list(schedule.items()) + list(additions.items()))
|
2023-05-04 19:46:37 +03:00
|
|
|
|
return full_schedule
|
|
|
|
|
|
|
|
|
|
if (self.MESSAGE["text"].lower() == "!пара" or self.MESSAGE["text"].lower().split()[0] == "!пари"):
|
2023-04-27 11:22:25 +03:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
#getting current time
|
|
|
|
|
current_time = datetime.datetime.now()
|
|
|
|
|
|
|
|
|
|
current_week = current_time.isocalendar()[1] % 2
|
|
|
|
|
current_day = current_time.weekday()
|
|
|
|
|
current_seconds = current_week*604800 + current_day*86400 + current_time.hour*3600 + current_time.minute*60 + current_time.second
|
|
|
|
|
reference_time = int(current_time.strftime("%s")) - current_seconds
|
|
|
|
|
|
|
|
|
|
full_schedule = get_full_schedule()
|
|
|
|
|
|
|
|
|
|
if self.MESSAGE["text"].lower() == "!пара":
|
|
|
|
|
print("test1")
|
|
|
|
|
print(f"Full schedule printout: {full_schedule}")
|
|
|
|
|
print(f"Current delta_time: {current_seconds}")
|
|
|
|
|
lesson = None
|
|
|
|
|
next_lesson_time = None
|
|
|
|
|
|
|
|
|
|
key_list = list(full_schedule.keys())
|
|
|
|
|
key_list.sort()
|
|
|
|
|
for i in key_list:
|
|
|
|
|
if i > current_seconds - 5400:
|
|
|
|
|
lesson = full_schedule[i]
|
|
|
|
|
next_lesson_time = i
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
print("test2")
|
|
|
|
|
if next_lesson_time == None:
|
|
|
|
|
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
|
|
|
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
|
|
|
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
|
|
|
|
|
|
|
|
|
if len(full_schedule.keys()) > 0:
|
|
|
|
|
print("test3.1")
|
|
|
|
|
lesson = full_schedule[min(full_schedule.keys())]
|
|
|
|
|
print("test3.1.1")
|
|
|
|
|
|
|
|
|
|
print("{} == 6 && {} == 1, {}".format(current_day, dt_lesson.strftime('%u'), str( ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")) )))
|
|
|
|
|
|
|
|
|
|
human_readable_date = ""
|
|
|
|
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
|
|
|
|
human_readable_date += "завтра "
|
|
|
|
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
|
|
|
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
|
|
|
|
else:
|
|
|
|
|
human_readable_date += "сьогодні "
|
|
|
|
|
|
|
|
|
|
print("test3.1.2")
|
|
|
|
|
|
|
|
|
|
human_readable_date += "з "
|
|
|
|
|
|
|
|
|
|
print("test3.1.3")
|
|
|
|
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
|
|
|
|
print("test3.1.4")
|
|
|
|
|
|
|
|
|
|
human_readable_date += " до "
|
|
|
|
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
|
|
|
|
|
|
|
|
|
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(lesson['name'], human_readable_date, lesson['teacher'], lesson['link'])
|
|
|
|
|
print("test3.1.5")
|
|
|
|
|
else:
|
|
|
|
|
self.RESPONCE = "Пар немає взагалі. Ми вільні!"
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print("test3.2")
|
|
|
|
|
actual_lesson_ts = reference_time + next_lesson_time
|
|
|
|
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
|
|
|
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
2023-02-25 15:54:16 +02:00
|
|
|
|
|
|
|
|
|
human_readable_date = ""
|
2023-04-27 11:22:25 +03:00
|
|
|
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
2023-02-25 15:54:16 +02:00
|
|
|
|
human_readable_date += "завтра "
|
2023-04-27 11:22:25 +03:00
|
|
|
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
|
|
|
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
2023-02-25 15:54:16 +02:00
|
|
|
|
else:
|
|
|
|
|
human_readable_date += "сьогодні "
|
|
|
|
|
|
2023-02-26 10:28:31 +02:00
|
|
|
|
human_readable_date += "з "
|
2023-04-27 11:22:25 +03:00
|
|
|
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
2023-02-25 15:54:16 +02:00
|
|
|
|
|
2023-02-26 10:28:31 +02:00
|
|
|
|
human_readable_date += " до "
|
2023-04-27 11:22:25 +03:00
|
|
|
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
2023-02-26 10:28:31 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
self.RESPONCE = "Актуальна пара: {}\nДата: {}\nВикладач: {}\nПосилання на пару: {}".format(lesson['name'], human_readable_date, lesson['teacher'], lesson['link'])
|
|
|
|
|
|
|
|
|
|
if self.MESSAGE["text"].lower().split()[0] == "!пари":
|
|
|
|
|
command = self.MESSAGE["text"].lower().split()
|
|
|
|
|
|
|
|
|
|
preferences = {"name": True, "date": True, "teacher": True, "link": True}
|
|
|
|
|
selected_day = current_week*7 + current_day
|
|
|
|
|
|
|
|
|
|
if len(command) >= 2 and len(command[1]) > 0:
|
|
|
|
|
if command[1][0] == "+":
|
|
|
|
|
try:
|
|
|
|
|
selected_day += int(command[1][1:])
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"[auto-schedule-pro:error] Got exception '{e}' while parsing {command[1]}")
|
|
|
|
|
elif command[1][0] == "-":
|
|
|
|
|
try:
|
|
|
|
|
selected_day -= int(command[1][1:])
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"[auto-schedule-pro:error] Got exception '{e}' while parsing {command[1]}")
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
selected_day = int(command[1])
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"[auto-schedule-pro:error] Got exception '{e}' while parsing {command[1]}")
|
|
|
|
|
|
|
|
|
|
# keeping day in bounds
|
|
|
|
|
selected_day = selected_day % 14
|
|
|
|
|
|
|
|
|
|
if len(command) > 2:
|
|
|
|
|
for i in command[2:]:
|
|
|
|
|
if len(i) >= 2:
|
|
|
|
|
if i[1:] in preferences:
|
|
|
|
|
if i[0] == "+":
|
|
|
|
|
preferences[i[1:]] = True
|
|
|
|
|
elif i[0] == "-":
|
|
|
|
|
preferences[i[1:]] = False
|
|
|
|
|
|
|
|
|
|
found_lessons = {}
|
|
|
|
|
for i in full_schedule:
|
|
|
|
|
if selected_day*86400 <= i < (selected_day+1)*86400:
|
|
|
|
|
found_lessons[i] = dict(full_schedule[i])
|
|
|
|
|
|
|
|
|
|
result_text = f"Пари у {self.WEEKDAYS_ACCUSATIVE[selected_day%7]}:\n\n"
|
|
|
|
|
for i in found_lessons:
|
|
|
|
|
actual_lesson_ts = reference_time + i
|
|
|
|
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
|
|
|
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
|
|
|
|
lesson = found_lessons[i]
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
human_readable_date = ""
|
|
|
|
|
if ((current_day + 2) == int(dt_lesson.strftime("%u"))) or ((str(current_day) == "6") and (dt_lesson.strftime("%u") == "1")):
|
|
|
|
|
human_readable_date += "завтра "
|
|
|
|
|
elif current_week != int(dt_lesson.strftime("%W")) % 2:
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_NEXT[int(dt_lesson.strftime("%u")) - 1])
|
|
|
|
|
elif current_day != (int(dt_lesson.strftime("%u")) - 1):
|
|
|
|
|
human_readable_date += "{} ".format(self.WEEKDAYS_GENITIVE_THIS[int(dt_lesson.strftime("%u")) - 1])
|
|
|
|
|
else:
|
|
|
|
|
human_readable_date += "сьогодні "
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
human_readable_date += "з "
|
|
|
|
|
human_readable_date += dt_lesson.strftime("%H:%M")
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
human_readable_date += " до "
|
|
|
|
|
human_readable_date += dt_lesson_finish.strftime("%H:%M")
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
if preferences['name']:
|
|
|
|
|
result_text += f"Назва: {lesson['name']}\n"
|
|
|
|
|
if preferences['date']:
|
|
|
|
|
result_text += f"Дата: {human_readable_date}\n"
|
|
|
|
|
if preferences['teacher']:
|
|
|
|
|
result_text += f"Викладач: {lesson['teacher']}\n"
|
|
|
|
|
if preferences['link']:
|
|
|
|
|
result_text += f"Посилання на пару: {lesson['link']}\n"
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
result_text += "\n"
|
2023-03-04 16:44:44 +02:00
|
|
|
|
|
2023-05-04 19:46:37 +03:00
|
|
|
|
self.RESPONCE = result_text
|