PEP8 autoformat and message formatting changes. #9
8
main.py
8
main.py
|
@ -98,7 +98,7 @@ class ModuleControlUnit:
|
||||||
print(f"[WARN] module_loader: no meta.json found in module folder \"{folder}\"")
|
print(f"[WARN] module_loader: no meta.json found in module folder \"{folder}\"")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
meta = json.loads( meta_raw )
|
meta = json.loads(meta_raw)
|
||||||
if "version" in meta:
|
if "version" in meta:
|
||||||
if meta["version"] == 1:
|
if meta["version"] == 1:
|
||||||
if "index_file" in meta:
|
if "index_file" in meta:
|
||||||
|
@ -106,7 +106,7 @@ class ModuleControlUnit:
|
||||||
else:
|
else:
|
||||||
index_file = "index.py"
|
index_file = "index.py"
|
||||||
|
|
||||||
code = readfile( "modules/{}/{}".format(folder, index_file) )
|
code = readfile("modules/{}/{}".format(folder, index_file))
|
||||||
if not code: # False both when readfile() returns False and when the code string is empty
|
if not code: # False both when readfile() returns False and when the code string is empty
|
||||||
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
||||||
continue
|
continue
|
||||||
|
@ -205,7 +205,8 @@ def queue_processor():
|
||||||
updater.bot.send_message(chat_id=msg.chat.id, text=response,
|
updater.bot.send_message(chat_id=msg.chat.id, text=response,
|
||||||
disable_web_page_preview=True,
|
disable_web_page_preview=True,
|
||||||
parse_mode=formatting)
|
parse_mode=formatting)
|
||||||
print(f"Responded using module {mod.path} ({mod.alias}) with text (using {formatting}): {response}")
|
print(
|
||||||
|
f"Responded using module {mod.path} ({mod.alias}) with text (using {formatting}): {response}")
|
||||||
break
|
break
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
|
@ -247,7 +248,6 @@ mcu = ModuleControlUnit()
|
||||||
processor_thread = threading.Thread(target=queue_processor, args=[])
|
processor_thread = threading.Thread(target=queue_processor, args=[])
|
||||||
processor_thread.start()
|
processor_thread.start()
|
||||||
|
|
||||||
|
|
||||||
# connecting to Telegram servers and listening for messages
|
# connecting to Telegram servers and listening for messages
|
||||||
|
|
||||||
TOKEN = readfile("config/token")
|
TOKEN = readfile("config/token")
|
||||||
|
|
|
@ -24,10 +24,10 @@ lesson_types_to_strings = {
|
||||||
"lab": "лабораторна"
|
"lab": "лабораторна"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
module_path = ""
|
module_path = ""
|
||||||
|
|
||||||
|
|
||||||
def escaped_string_markdownV2(input_string):
|
def escaped_string_markdownV2(input_string):
|
||||||
result_string = input_string
|
result_string = input_string
|
||||||
|
|
||||||
|
@ -85,21 +85,21 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
if output_settings['name']:
|
if output_settings['name']:
|
||||||
result += f"{custom_name_prefix}: {escaped_string_html(lesson['name'])} ({escaped_string_html(get_name_of_lesson_type(lesson['type']))})\n"
|
result += f"<b>{escaped_string_html(lesson['name'])}<b> ({escaped_string_html(get_name_of_lesson_type(lesson['type']))})\n"
|
||||||
|
|
||||||
if output_settings['date']:
|
if output_settings['date']:
|
||||||
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
||||||
current_day, current_week)
|
current_day, current_week)
|
||||||
result += f"<b>Дата</b>: {escaped_string_html(human_readable_date)}\n"
|
result += f"<i>Дата</ii>: {escaped_string_html(human_readable_date)}\n"
|
||||||
|
|
||||||
if output_settings['teacher']:
|
if output_settings['teacher']:
|
||||||
result += f"<b>Викладач</b>: {escaped_string_html(lesson['teacher'])}\n"
|
result += f"<i>Викладач</i>: {escaped_string_html(lesson['teacher'])}\n"
|
||||||
|
|
||||||
if output_settings['link']:
|
if output_settings['link']:
|
||||||
result += f"<b>Посилання</b>: {escaped_string_html(lesson['link'])}\n"
|
result += f"<i>Посилання</i>: {escaped_string_html(lesson['link'])}\n"
|
||||||
|
|
||||||
if output_settings['comment'] and 'comment' in lesson:
|
if output_settings['comment'] and 'comment' in lesson:
|
||||||
result += f"<b>Примітка</b>: {escaped_string_html(lesson['comment'])}\n"
|
result += f"<i>Примітка</i>: {escaped_string_html(lesson['comment'])}\n"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -163,7 +163,8 @@ def get_lesson_description(schedule, reference_time, lesson_time, current_day, c
|
||||||
internal_overrides = dict(overrides)
|
internal_overrides = dict(overrides)
|
||||||
internal_overrides['date'] = False
|
internal_overrides['date'] = False
|
||||||
|
|
||||||
description = generate_lesson_description(lesson_record, lesson_start_datetime, lesson_end_datetime, current_day,
|
description = generate_lesson_description(lesson_record, lesson_start_datetime, lesson_end_datetime,
|
||||||
|
current_day,
|
||||||
current_week, overrides=internal_overrides)
|
current_week, overrides=internal_overrides)
|
||||||
|
|
||||||
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
||||||
|
@ -182,7 +183,8 @@ def get_lesson_description(schedule, reference_time, lesson_time, current_day, c
|
||||||
internal_overrides['date'] = False
|
internal_overrides['date'] = False
|
||||||
|
|
||||||
descriptions = [generate_lesson_description(i, lesson_start_datetime, lesson_end_datetime, current_day,
|
descriptions = [generate_lesson_description(i, lesson_start_datetime, lesson_end_datetime, current_day,
|
||||||
current_week, overrides=internal_overrides, custom_name_prefix=custom_name_prefix) for i in lesson_record]
|
current_week, overrides=internal_overrides,
|
||||||
|
custom_name_prefix=custom_name_prefix) for i in lesson_record]
|
||||||
|
|
||||||
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
||||||
return "\n".join(descriptions)
|
return "\n".join(descriptions)
|
||||||
|
@ -224,7 +226,7 @@ def process(message, path):
|
||||||
study_begin_ts = int(datetime(year=2023, month=9, day=4).strftime("%s"))
|
study_begin_ts = int(datetime(year=2023, month=9, day=4).strftime("%s"))
|
||||||
current_ts = int(datetime.now().strftime("%s"))
|
current_ts = int(datetime.now().strftime("%s"))
|
||||||
|
|
||||||
if -3600*4 < study_begin_ts - current_ts < 0:
|
if -3600 * 4 < study_begin_ts - current_ts < 0:
|
||||||
return "Навчання незабаром розпочнеться!", None
|
return "Навчання незабаром розпочнеться!", None
|
||||||
elif 0 <= study_begin_ts - current_ts < 1209600:
|
elif 0 <= study_begin_ts - current_ts < 1209600:
|
||||||
return f"До навчання залишилося {study_begin_ts - current_ts} секунд...", None
|
return f"До навчання залишилося {study_begin_ts - current_ts} секунд...", None
|
||||||
|
@ -254,7 +256,9 @@ def process(message, path):
|
||||||
lesson_list = [i for i in schedule if selected_day * 86400 <= i < (selected_day + 1) * 86400]
|
lesson_list = [i for i in schedule if selected_day * 86400 <= i < (selected_day + 1) * 86400]
|
||||||
|
|
||||||
lesson_descriptions_list = [get_lesson_description(schedule, reference_time, lesson_time, current_day,
|
lesson_descriptions_list = [get_lesson_description(schedule, reference_time, lesson_time, current_day,
|
||||||
current_week, overrides=preferences, custom_name_prefix="<b>Назва</b>", force_date_at_top=True)
|
current_week, overrides=preferences,
|
||||||
|
custom_name_prefix="<b>Назва</b>", force_date_at_top=True)
|
||||||
for lesson_time in lesson_list]
|
for lesson_time in lesson_list]
|
||||||
|
|
||||||
return f"<b><u>Пари у {WEEKDAYS_ACCUSATIVE[selected_day % 7]}</u></b>:\n\n\n" + "\n\n".join(lesson_descriptions_list), "HTML"
|
return f"<b><u>Пари у {WEEKDAYS_ACCUSATIVE[selected_day % 7]}</u></b>:\n\n\n" + "\n\n".join(
|
||||||
|
lesson_descriptions_list), "HTML"
|
||||||
|
|
Loading…
Reference in New Issue