auto-schedule-pro-v2: add short lesson listing format to improve readability
This commit is contained in:
parent
c283414fe3
commit
c881d54a4e
|
@ -28,6 +28,13 @@ lesson_types_to_strings = {
|
|||
"con": "консультація"
|
||||
}
|
||||
|
||||
color_code_mapping = {
|
||||
"lec": "🔵",
|
||||
"prac": "🟡",
|
||||
"lab": "🔴",
|
||||
"con": "🟢"
|
||||
}
|
||||
|
||||
|
||||
# global variables
|
||||
module_path = ""
|
||||
|
@ -114,6 +121,10 @@ def load_template(template, part):
|
|||
return readfile(f"templates/{template}/{part}.msg")
|
||||
|
||||
|
||||
def get_color_code(lesson_type):
|
||||
return color_code_mapping[lesson_type]
|
||||
|
||||
|
||||
def escaped_string_markdownV2(input_string):
|
||||
result_string = input_string
|
||||
|
||||
|
@ -165,9 +176,6 @@ def get_name_of_lesson_type(lesson_type):
|
|||
|
||||
def generate_lesson_description(lesson, start_datetime, end_datetime, current_day, current_week, overrides={},
|
||||
custom_name_prefix="Назва", template="legacy-vibrant", force_date_at_top=False):
|
||||
# temporarily not supported
|
||||
#output_settings = {"name": True, "date": True, "teacher": True, "link": True, "comment": True}
|
||||
#output_settings.update(overrides)
|
||||
|
||||
if lesson.__class__ == dict:
|
||||
if force_date_at_top:
|
||||
|
@ -176,33 +184,51 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da
|
|||
current_day, current_week)
|
||||
total_result = total_result.replace("%DATE%", human_readable_date)
|
||||
|
||||
total_result += load_template(template, "multiple")
|
||||
for i in ['name', 'teacher', 'link']:
|
||||
if "full" in overrides and overrides["full"]:
|
||||
total_result += load_template(template, "multiple")
|
||||
else:
|
||||
total_result += load_template(template, "multiple-short")
|
||||
|
||||
for i in ['name', 'teacher']:
|
||||
total_result = total_result.replace(f"%{i.upper()}%", lesson[i])
|
||||
|
||||
total_result = total_result.replace("%DATE%", human_readable_date)
|
||||
total_result = total_result.replace("%TYPE%", get_name_of_lesson_type(lesson['type']))
|
||||
total_result = total_result.replace("%NAME_PREFIX%", custom_name_prefix)
|
||||
total_result = total_result.replace("%COLOR_CODE%", get_color_code(lesson['type']))
|
||||
|
||||
if ('nolink' not in lesson) or (not lesson['nolink']):
|
||||
total_result = total_result.replace("%LINK%", lesson['link'])
|
||||
else:
|
||||
total_result = total_result.replace("%LINK%", "#")
|
||||
|
||||
if 'comment' in lesson:
|
||||
total_result += load_template(template, "comment")
|
||||
total_result = total_result.replace("%COMMENT%", lesson["comment"])
|
||||
|
||||
return total_result + "\n"
|
||||
if "full" in overrides and overrides["full"]:
|
||||
total_result += "\n"
|
||||
|
||||
return total_result
|
||||
|
||||
else:
|
||||
active_template = load_template(template, "single")
|
||||
|
||||
for i in ['name', 'teacher', 'link']:
|
||||
for i in ['name', 'teacher']:
|
||||
active_template = active_template.replace(f"%{i.upper()}%", lesson[i])
|
||||
|
||||
|
||||
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
||||
current_day, current_week)
|
||||
|
||||
active_template = active_template.replace("%DATE%", human_readable_date)
|
||||
active_template = active_template.replace("%TYPE%", get_name_of_lesson_type(lesson['type']))
|
||||
active_template = active_template.replace("%NAME_PREFIX%", custom_name_prefix)
|
||||
active_template = active_template.replace("%COLOR_CODE%", get_color_code(lesson['type']))
|
||||
|
||||
if ('nolink' not in lesson) or (not lesson['nolink']):
|
||||
active_template = active_template.replace("%LINK%", lesson['link'])
|
||||
else:
|
||||
active_template = active_template.replace("%LINK%", "#")
|
||||
|
||||
if 'comment' in lesson:
|
||||
active_template += load_template(template, "comment")
|
||||
|
@ -213,24 +239,36 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da
|
|||
elif lesson.__class__ == list:
|
||||
total_result = load_template(template, "date")
|
||||
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
||||
current_day, current_week)
|
||||
current_day, current_week)
|
||||
total_result = total_result.replace("%DATE%", human_readable_date)
|
||||
|
||||
for l in lesson:
|
||||
active_template = load_template(template, "multiple")
|
||||
if "full" in overrides and overrides["full"]:
|
||||
active_template = load_template(template, "multiple")
|
||||
else:
|
||||
active_template = load_template(template, "multiple-short")
|
||||
|
||||
for i in ['name', 'teacher', 'link']:
|
||||
for i in ['name', 'teacher']:
|
||||
active_template = active_template.replace(f"%{i.upper()}%", l[i])
|
||||
|
||||
active_template = active_template.replace("%DATE%", human_readable_date)
|
||||
active_template = active_template.replace("%TYPE%", get_name_of_lesson_type(l['type']))
|
||||
active_template = active_template.replace("%NAME_PREFIX%", custom_name_prefix)
|
||||
active_template = active_template.replace("%COLOR_CODE%", get_color_code(l['type']))
|
||||
|
||||
if ('nolink' not in lesson) or (not lesson['nolink']):
|
||||
active_template = active_template.replace("%LINK%", l['link'])
|
||||
else:
|
||||
active_template = active_template.replace("%LINK%", "#")
|
||||
|
||||
if 'comment' in lesson:
|
||||
total_result += load_template(template, "comment")
|
||||
total_result = total_result.replace("%COMMENT%", lesson["comment"])
|
||||
active_template += load_template(template, "comment")
|
||||
active_template = active_template.replace("%COMMENT%", lesson["comment"])
|
||||
|
||||
total_result += active_template + "\n"
|
||||
if "full" in overrides and overrides["full"]:
|
||||
active_template += "\n"
|
||||
|
||||
total_result += active_template
|
||||
|
||||
return total_result
|
||||
|
||||
|
@ -324,19 +362,20 @@ def process(message, path):
|
|||
|
||||
if base_command in ["!пара", "!para"]:
|
||||
# easter egg
|
||||
study_begin_ts = int(datetime(year=2024, month=2, day=5).strftime("%s"))
|
||||
study_begin_ts = int(datetime(year=2024, month=9, day=2).strftime("%s"))
|
||||
current_ts = int(datetime.now().strftime("%s"))
|
||||
|
||||
until_study_day = study_begin_ts - current_ts
|
||||
|
||||
if -3600*4 < until_study_day < 0:
|
||||
return "Навчання от-от розпочнеться!", None
|
||||
elif 0 <= until_study_day < 3600*24*14:
|
||||
elif 0 <= until_study_day < 3600*24*28:
|
||||
return f"До навчання залишилося {until_study_day} секунд..." \
|
||||
f" ({round(until_study_day/3600, 4)} годин," \
|
||||
f" {round(until_study_day/3600/24, 4)} діб)", None
|
||||
elif until_study_day >= 3600*24*14:
|
||||
return "Ви маєте законне право відпочити, пари почнуться не скоро", None
|
||||
|
||||
|
||||
# actual lesson finding code
|
||||
upcoming_lessons = [timestamp for timestamp in schedule if timestamp > current_seconds - 5400]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<b><a href="%LINK%">%COLOR_CODE% %NAME%</a></b>
|
|
@ -0,0 +1 @@
|
|||
<a href="%LINK%">%COLOR_CODE% %NAME%</a>
|
|
@ -0,0 +1 @@
|
|||
<b><a href="%LINK%">%COLOR_CODE% %NAME%</a></b>
|
Loading…
Reference in New Issue