|
|
|
@ -36,6 +36,9 @@ color_code_mapping = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROGRESS_BAR_LENGTH = 16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# global variables
|
|
|
|
|
module_path = ""
|
|
|
|
|
|
|
|
|
@ -174,6 +177,37 @@ def get_name_of_lesson_type(lesson_type):
|
|
|
|
|
return lesson_types_to_strings[lesson_type]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_progress_bar(start_datetime, total_bar_count):
|
|
|
|
|
current_time = datetime.now()
|
|
|
|
|
|
|
|
|
|
seconds_elapsed = (current_time.hour - start_datetime.hour) * 3600 \
|
|
|
|
|
+ (current_time.minute - start_datetime.minute) * 60 \
|
|
|
|
|
+ (current_time.second - start_datetime.second)
|
|
|
|
|
|
|
|
|
|
total_seconds = 1 * 3600 + 30 * 60
|
|
|
|
|
|
|
|
|
|
percent_elapsed = max(min(seconds_elapsed / total_seconds, 1), 0)
|
|
|
|
|
|
|
|
|
|
if (current_time.day < start_datetime.day):
|
|
|
|
|
percent_elapsed = 0
|
|
|
|
|
elif (current_time.day > start_datetime.day):
|
|
|
|
|
percent_elapsed = 1
|
|
|
|
|
|
|
|
|
|
bars_ticked = round(percent_elapsed * total_bar_count)
|
|
|
|
|
bars_not_ticked = total_bar_count - bars_ticked
|
|
|
|
|
|
|
|
|
|
status_line = "[" + "#" * bars_ticked + "-" * bars_not_ticked + "]"
|
|
|
|
|
|
|
|
|
|
status_bar_text = f"{round(percent_elapsed*100)}%"
|
|
|
|
|
|
|
|
|
|
status_list_text_start_position = round((len(status_line) - len(status_bar_text))/2)
|
|
|
|
|
|
|
|
|
|
status_line_overlayed = (status_line[:status_list_text_start_position] + status_bar_text \
|
|
|
|
|
+ status_line[status_list_text_start_position+len(status_bar_text):]).replace("-", "--")
|
|
|
|
|
|
|
|
|
|
return status_line_overlayed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
|
|
|
|
|
@ -224,6 +258,7 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da
|
|
|
|
|
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']))
|
|
|
|
|
active_template = active_template.replace("%PROGRESS_BAR%", make_progress_bar(start_datetime, PROGRESS_BAR_LENGTH >> 1))
|
|
|
|
|
|
|
|
|
|
if ('nolink' not in lesson) or (not lesson['nolink']):
|
|
|
|
|
active_template = active_template.replace("%LINK%", lesson['link'])
|
|
|
|
@ -237,11 +272,17 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da
|
|
|
|
|
return active_template
|
|
|
|
|
|
|
|
|
|
elif lesson.__class__ == list:
|
|
|
|
|
if not force_date_at_top:
|
|
|
|
|
total_result = load_template(template, "date-progress")
|
|
|
|
|
total_result = total_result.replace("%PROGRESS_BAR%", make_progress_bar(start_datetime, PROGRESS_BAR_LENGTH))
|
|
|
|
|
else:
|
|
|
|
|
total_result = load_template(template, "date")
|
|
|
|
|
|
|
|
|
|
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
|
|
|
|
current_day, current_week)
|
|
|
|
|
total_result = total_result.replace("%DATE%", human_readable_date)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for l in lesson:
|
|
|
|
|
if "full" in overrides and overrides["full"]:
|
|
|
|
|
active_template = load_template(template, "multiple")
|
|
|
|
|