From bfed31c890d05567fbc0b5d52923a7b0ebdc0e1a Mon Sep 17 00:00:00 2001 From: Anry Das Date: Sun, 18 Jan 2026 09:29:49 +0200 Subject: [PATCH] Improved informer --- get_eo.py | 144 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 33 deletions(-) diff --git a/get_eo.py b/get_eo.py index 0ff8f7e..95c3b69 100644 --- a/get_eo.py +++ b/get_eo.py @@ -221,6 +221,7 @@ def get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue need_to_send = not is_old_and_new_datas_equals_GPV(hours_off, hours_on, approved_from, event_date) if need_to_send: save_last_datas_GPV(hours_off, hours_on, approved_from, event_date) + if len(hours_off) > 0: message += '\nВимкнення:' for i in range(len(hours_off)): @@ -295,16 +296,92 @@ def get_message_with_PO(root, def process_GPV(oe_account_number, tg_chat, tg_token): global IS_DEBUG - if not IS_DEBUG: + if IS_DEBUG: + x = json.loads( + # '{"current": {"hasQueue": "yes", "note": "ZZZ xxx YYY", "queue": 5, "subQueue": 1}, "schedule": [{"createdAt": "30.10.2025 20:59", "eventDate": "31.10.2025", "queues": {"5.1": [{"from": "22:00", "shutdownHours": "22:00-00:00", "status": 1, "to": "00:00"}]}, "scheduleApprovedSince": "31.10.2025 10:52"}]}' + """{ +"current": + { + "gav": + { + "message": "Черга спеціальних аварійних відключень (СГАВ):", + "queue": null + }, + "hasQueue": "yes", + "note": "Станом на 21:05 14.01.2026 за вказаним особовим рахунком '30014180' споживач підпадає під чергу '5.1' Графіку погодинного відключення(ГПВ)", + "queue": 5, + "sgav": + { + "message": "Черга спеціальних аварійних відключень (СГАВ):", + "queue": null + }, + "subQueue": 1 + }, +"schedule": + [ + { + "createdAt": "14.01.2026 19:11", + "eventDate": "15.01.2026", + "queues": + { + "5.1": + [ + { + "from": "07:30", + "shutdownHours": "07:30-11:00", + "status": 1, + "to": "11:00" + }, + { + "from": "14:30", + "shutdownHours": "14:30-20:00", + "status": 1, + "to": "20:00" + }, + { + "from": "22:00", + "shutdownHours": "22:00-00:00", + "status": 1, + "to": "00:00" + } + ] + }, + "scheduleApprovedSince": "14.01.2026 19:11" + }, + { + "createdAt": "13.01.2026 20:28", + "eventDate": "14.01.2026", + "queues": + { + "5.1": + [ + { + "from": "03:00", + "shutdownHours": "03:00-07:00", + "status": 1, + "to": "07:00" + }, + { + "from": "11:00", + "shutdownHours": "11:00-17:30", + "status": 1, + "to": "17:30" + } + ] + }, + "scheduleApprovedSince": "14.01.2026 09:56" + } + ] +} + """ + ) + else: response = get_GPV_response_from_oe(oe_account_number) if response.status_code != 200: print("code=" + str(response.status_code)) return STATUS_ERROR_GPV_RESPONSE x = response.json() - else: - x = json.loads( - '{"current": {"hasQueue": "yes", "note": "ZZZ xxx YYY", "queue": 5, "subQueue": 1}, "schedule": [{"createdAt": "30.10.2025 20:59", "eventDate": "31.10.2025", "queues": {"5.1": [{"from": "22:00", "shutdownHours": "22:00-00:00", "status": 1, "to": "00:00"}]}, "scheduleApprovedSince": "31.10.2025 10:52"}]}') hours_off = [] hours_on = [] @@ -314,43 +391,44 @@ def process_GPV(oe_account_number, tg_chat, tg_token): datas = '' if 'queues' in str(x["schedule"]): - datas = x["schedule"][0] + datas = sorted(x["schedule"], key=lambda item: item['eventDate']) - if len(datas) > 0: - approved_from = 'Запроваджено ' + datas['scheduleApprovedSince'] - event_date = datas['eventDate'] - hours_list = datas['queues'][outage_queue] - else: - hours_list = [] - approved_from = 'Hемає даних про дату запровадження' - event_date = dt.today().strftime('%Y-%m-%d') + for entry in datas: + if len(entry) > 0: + approved_from = 'Запроваджено ' + entry['scheduleApprovedSince'] + event_date = entry['eventDate'] + hours_list = entry['queues'][outage_queue] + else: + hours_list = [] + approved_from = 'Hемає даних про дату запровадження' + event_date = dt.today().strftime('%Y-%m-%d') - if IS_DEBUG: - print(f'hours_list{hours_list}, approved_from={approved_from}, event_date={event_date}') + if IS_DEBUG: + print(f'hours_list{hours_list}, approved_from={approved_from}, event_date={event_date}') - for h in hours_list: - if h["status"] == 1: - hours_off.append(h["from"]) - hours_on.append(h["to"]) + for h in hours_list: + if h["status"] == 1: + hours_off.append(h["from"]) + hours_on.append(h["to"]) - if IS_DEBUG: - print(f'hours_off = {hours_off}') - print(f'hours_on = {hours_on}') + if IS_DEBUG: + print(f'hours_off = {hours_off}') + print(f'hours_on = {hours_on}') - message, need_to_send = get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue) + message, need_to_send = get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue) - if IS_DEBUG: - print(f'{message}\nneed_to_send={need_to_send}') + if IS_DEBUG: + print(f'{message}\nneed_to_send={need_to_send}') - if need_to_send and not IS_DEBUG: - tg_response = send_message_to_tg(message, tg_token, tg_chat) - if tg_response.status_code != 200: - sys.exit(STATUS_ERROR_SEND_TO_TG) + if need_to_send and not IS_DEBUG: + tg_response = send_message_to_tg(message, tg_token, tg_chat) + if tg_response.status_code != 200: + sys.exit(STATUS_ERROR_SEND_TO_TG) - if USE_MATRIX: - res = send_matrix_notification(message) - if not res: - sys.exit(STATUS_ERROR_SEND_TO_MX) + if USE_MATRIX: + res = send_matrix_notification(message) + if not res: + sys.exit(STATUS_ERROR_SEND_TO_MX) def process_PO(apart, house, part_number, settlement, street, tg_chat, tg_token):