From 76c6bd3c0e28080195be1fd5388adfe9c7e642ed Mon Sep 17 00:00:00 2001 From: dymik739 Date: Fri, 4 Nov 2022 20:12:48 +0200 Subject: [PATCH] Added new module: auto-schedule --- modules/auto-schedule/index.py | 41 +++++++++++++++++++++++++++++ modules/auto-schedule/meta.json | 7 +++++ modules/auto-schedule/predefine.py | 1 + modules/auto-schedule/schedule.json | 1 + 4 files changed, 50 insertions(+) create mode 100644 modules/auto-schedule/index.py create mode 100644 modules/auto-schedule/meta.json create mode 100644 modules/auto-schedule/predefine.py create mode 100644 modules/auto-schedule/schedule.json diff --git a/modules/auto-schedule/index.py b/modules/auto-schedule/index.py new file mode 100644 index 0000000..485c3bd --- /dev/null +++ b/modules/auto-schedule/index.py @@ -0,0 +1,41 @@ +if self.MESSAGE.text.lower() == "!пара": + try: + schedule = json.loads( readfile(self.path + "schedule.json") ) + + current_time = datetime.datetime.now() + + current_week = current_time.isocalendar()[1] % 2 + current_day = current_time.weekday() - 1 + current_seconds = current_time.hour * 3600 + current_time.minute * 60 + current_time.second + + if current_day > 4: + next_week = int(not bool(current_week)) + day = -1 + + next_pair = None + + pair_found = False + for i in schedule[next_week]: + if not pair_found: + day += 1 + for j in schedule[next_week][i]: + next_pair = schedule[next_week][i][j] + pair_found = True + break + + self.RESPONCE = "Сьогодні вихідний, тому пар немає)\nНаступна пара - {} ({}) у {}\nПосилання (якщо воно чомусь треба): {}".format(next_pair["subject"], next_pair["lector"], self.days[day], next_pair["link"]) + else: + for i in self.timetable: + if current_seconds < i: + print("[DEBUG] Looking up a relevant pair...") + try: + relevant_pair = schedule[current_week][current_day + 1][str(self.timetable[i])] + self.RESPONCE = "Актуальна пара: {} ({})\nПосилання: {}".format(relevant_pair["subject"], relevant_pair["lector"], relevant_pair["link"]) + break + except Exception as e: + print("[WARN] module: auto-schedule: exception {} while looking up the pair".format(e)) + else: + self.RESPONCE = "Сьогодні більше немає пар" + + except Exception as e: + print("[WARN] module: auto-schedule: failed to process schedule.json ({})".format(e)) diff --git a/modules/auto-schedule/meta.json b/modules/auto-schedule/meta.json new file mode 100644 index 0000000..8ce5659 --- /dev/null +++ b/modules/auto-schedule/meta.json @@ -0,0 +1,7 @@ +{ + "start_on_boot": true, + "alias": "auto-schedule", + "version": 1, + "index_file": "index.py", + "predefine": "predefine.py" +} diff --git a/modules/auto-schedule/predefine.py b/modules/auto-schedule/predefine.py new file mode 100644 index 0000000..6264603 --- /dev/null +++ b/modules/auto-schedule/predefine.py @@ -0,0 +1 @@ +self.timetable = {36300: 0, 43200: 1, 50100: 2, 57000: 3, 63900: 4, 72300: 5, 78900: 6} diff --git a/modules/auto-schedule/schedule.json b/modules/auto-schedule/schedule.json new file mode 100644 index 0000000..3d42d30 --- /dev/null +++ b/modules/auto-schedule/schedule.json @@ -0,0 +1 @@ +[ [{"0": {"link": "https://bbb.comsys.kpi.ua/b/ana-gca-2xm", "subject": "\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438 \u0434\u0430\u043d\u0438\u0445 \u0442\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438", "lector": "\u0421\u0435\u0440\u0433\u0456\u0454\u043d\u043a\u043e \u0410. \u041c."}, "1": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "2": {"link": "https://us02web.zoom.us/j/4387354937?pwd=R3R3NkpWU09GY3kvanZBeEcrQWZoUT09", "subject": "\u041e\u0441\u043d\u043e\u0432\u0438 \u0437\u0434\u043e\u0440\u043e\u0432\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0436\u0438\u0442\u0442\u044f", "lector": "\u0425\u0456\u043c\u0456\u0447 \u0406. \u042e."}, "3": {"link": "https://bbb.comsys.kpi.ua/b/dxa-2gr-2dc-odu", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041d\u043e\u0432\u043e\u0442\u0430\u0440\u0441\u044c\u043a\u0438\u0439 \u041c. \u0410."}}, {"1": {"link": "https://meet.google.com/fyi-bwkm-qyf", "subject": "\u0406\u0441\u0442\u043e\u0440\u0456\u044f \u043d\u0430\u0443\u043a\u0438 \u0439 \u0442\u0435\u0445\u043d\u0456\u043a\u0438", "lector": "\u0428\u0435\u0432\u0447\u0443\u043a \u0422. \u0412."}}, {"0": {"link": "https://meet.google.com/idu-adtd-rvr?authuser=0", "subject": " \u0406\u0441\u0442\u043e\u0440\u0456\u044f \u043d\u0430\u0443\u043a\u0438 \u0439 \u0442\u0435\u0445\u043d\u0456\u043a\u0438", "lector": "\u041a\u043e\u0441\u0442\u0438\u043b\u0454\u0432\u0430 \u0421. \u041e."}, "1": {"link": "https://us02web.zoom.us/j/4911162386?pwd=OU43Q0thZEk1bFhvcFBRUm13VXlZZz09", "subject": "\u0410\u043d\u0430\u043b\u0456\u0442\u0438\u0447\u043d\u0430 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0456\u044f \u0442\u0430 \u043b\u0456\u043d\u0456\u0439\u043d\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0430", "lector": "\u0412\u0430\u043d\u0454\u0454\u0432\u0430 \u041e. \u041e."}, "2": {"link": "https://bbb.comsys.kpi.ua/b/dxa-2gr-2dc-odu", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041d\u043e\u0432\u043e\u0442\u0430\u0440\u0441\u044c\u043a\u0438\u0439 \u041c. \u0410."}, "3": {"link": "https://bbb.comsys.kpi.ua/b/val-zdp-vw0-dbr", "subject": "\u041a\u043e\u043c\u043f'\u044e\u0442\u0435\u0440\u043d\u0430 \u043b\u043e\u0433\u0456\u043a\u0430", "lector": "\u0416\u0430\u0431\u0456\u043d \u0412. \u0406."}}, {"1": {"link": "https://meet.google.com/bwg-pdnr-evh", "subject": "\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u0438\u0439 \u043a\u0443\u0440\u0441 \u0456\u043d\u043e\u0437\u0435\u043c\u043d\u043e\u0457 \u043c\u043e\u0432\u0438", "lector": "\u0428\u0435\u0432\u0447\u0435\u043d\u043a\u043e \u041e. \u041c."}, "2": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "3": {"link": "https://us05web.zoom.us/j/7089075754?pwd=TWRlZmxyVlFiTWU1UGlVVU1XcFE0Zz09", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041f\u043e\u043d\u043e\u043c\u0430\u0440\u0435\u043d\u043a\u043e"}, "4": {"link": "https://us05web.zoom.us/j/7089075754?pwd=TWRlZmxyVlFiTWU1UGlVVU1XcFE0Zz09", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041f\u043e\u043d\u043e\u043c\u0430\u0440\u0435\u043d\u043a\u043e"}}, {"1": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "2": {"link": "https://us04web.zoom.us/j/7382214783?pwd=RnZ3SWgwK1JoVkZtNndnKzdPZjFGdz09", "subject": "\u041a\u043e\u043c\u043f'\u044e\u0442\u0435\u0440\u043d\u0430 \u043b\u043e\u0433\u0456\u043a\u0430", "lector": "\u0412\u0435\u0440\u0431\u0430 \u041e. \u0410."}}], [{"0": {"link": "https://bbb.comsys.kpi.ua/b/ana-gca-2xm", "subject": "\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438 \u0434\u0430\u043d\u0438\u0445 \u0442\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438", "lector": "\u0421\u0435\u0440\u0433\u0456\u0454\u043d\u043a\u043e \u0410. \u041c."}, "1": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "2": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "3": {"link": "https://bbb.comsys.kpi.ua/b/dxa-2gr-2dc-odu", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041d\u043e\u0432\u043e\u0442\u0430\u0440\u0441\u044c\u043a\u0438\u0439 \u041c. \u0410."}}, {}, {"1": {"link": "https://us02web.zoom.us/j/4911162386?pwd=OU43Q0thZEk1bFhvcFBRUm13VXlZZz09", "subject": "\u0410\u043d\u0430\u043b\u0456\u0442\u0438\u0447\u043d\u0430 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0456\u044f \u0442\u0430 \u043b\u0456\u043d\u0456\u0439\u043d\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0430", "lector": "\u0412\u0430\u043d\u0454\u0454\u0432\u0430 \u041e. \u041e."}, "2": {"link": "https://bbb.comsys.kpi.ua/b/dxa-2gr-2dc-odu", "subject": "\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f", "lector": "\u041d\u043e\u0432\u043e\u0442\u0430\u0440\u0441\u044c\u043a\u0438\u0439 \u041c. \u0410."}, "3": {"link": "https://bbb.comsys.kpi.ua/b/val-zdp-vw0-dbr", "subject": "\u041a\u043e\u043c\u043f'\u044e\u0442\u0435\u0440\u043d\u0430 \u043b\u043e\u0433\u0456\u043a\u0430", "lector": "\u0416\u0430\u0431\u0456\u043d \u0412. \u0406."}}, {"1": {"link": "https://meet.google.com/bwg-pdnr-evh", "subject": "\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u0438\u0439 \u043a\u0443\u0440\u0441 \u0456\u043d\u043e\u0437\u0435\u043c\u043d\u043e\u0457 \u043c\u043e\u0432\u0438", "lector": "\u0428\u0435\u0432\u0447\u0435\u043d\u043a\u043e \u041e. \u041c."}, "2": {"link": "https://us05web.zoom.us/j/81227675458?pwd=SWFuQTZLY2w5a2dMMjd0cTdxSUN6dz09", "subject": "\u0412\u0438\u0449\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430", "lector": "\u041e\u0440\u0434\u0438\u043d\u0441\u044c\u043a\u0430 \u0417. \u041f."}, "3": {"link": "https://us02web.zoom.us/j/4911162386?pwd=OU43Q0thZEk1bFhvcFBRUm13VXlZZz09", "subject": "\u0410\u043d\u0430\u043b\u0456\u0442\u0438\u0447\u043d\u0430 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0456\u044f \u0442\u0430 \u043b\u0456\u043d\u0456\u0439\u043d\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0430", "lector": "\u0412\u0430\u043d\u0454\u0454\u0432\u0430 \u041e. \u041e."}}, {"0": {"link": "https://zoom.us/j/2035574145?pwd=bk1wTVhGbjJsQTR4WmVQMlROWFBCZz09", "subject": " \u041e\u0441\u043d\u043e\u0432\u0438 \u0437\u0434\u043e\u0440\u043e\u0432\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0436\u0438\u0442\u0442\u044f", "lector": "\u0421\u043e\u0431\u043e\u043b\u0435\u043d\u043a\u043e \u0410. \u0406."}, "1": {"link": "https://us02web.zoom.us/j/88932218187?pwd=MUpFNjE3bHAxeEZ0NDE3NU0vYUUxZz09", "subject": "\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438 \u0434\u0430\u043d\u0438\u0445 \u0442\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438", "lector": "\u041c\u043e\u043b\u0447\u0430\u043d\u043e\u0432\u0430 \u0410. \u0410."}}] ]