Improved informer
This commit is contained in:
parent
c2b024e5df
commit
bfed31c890
144
get_eo.py
144
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)
|
need_to_send = not is_old_and_new_datas_equals_GPV(hours_off, hours_on, approved_from, event_date)
|
||||||
if need_to_send:
|
if need_to_send:
|
||||||
save_last_datas_GPV(hours_off, hours_on, approved_from, event_date)
|
save_last_datas_GPV(hours_off, hours_on, approved_from, event_date)
|
||||||
|
|
||||||
if len(hours_off) > 0:
|
if len(hours_off) > 0:
|
||||||
message += '\nВимкнення:'
|
message += '\nВимкнення:'
|
||||||
for i in range(len(hours_off)):
|
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):
|
def process_GPV(oe_account_number, tg_chat, tg_token):
|
||||||
global IS_DEBUG
|
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)
|
response = get_GPV_response_from_oe(oe_account_number)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print("code=" + str(response.status_code))
|
print("code=" + str(response.status_code))
|
||||||
return STATUS_ERROR_GPV_RESPONSE
|
return STATUS_ERROR_GPV_RESPONSE
|
||||||
|
|
||||||
x = response.json()
|
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_off = []
|
||||||
hours_on = []
|
hours_on = []
|
||||||
@ -314,43 +391,44 @@ def process_GPV(oe_account_number, tg_chat, tg_token):
|
|||||||
|
|
||||||
datas = ''
|
datas = ''
|
||||||
if 'queues' in str(x["schedule"]):
|
if 'queues' in str(x["schedule"]):
|
||||||
datas = x["schedule"][0]
|
datas = sorted(x["schedule"], key=lambda item: item['eventDate'])
|
||||||
|
|
||||||
if len(datas) > 0:
|
for entry in datas:
|
||||||
approved_from = 'Запроваджено ' + datas['scheduleApprovedSince']
|
if len(entry) > 0:
|
||||||
event_date = datas['eventDate']
|
approved_from = 'Запроваджено ' + entry['scheduleApprovedSince']
|
||||||
hours_list = datas['queues'][outage_queue]
|
event_date = entry['eventDate']
|
||||||
else:
|
hours_list = entry['queues'][outage_queue]
|
||||||
hours_list = []
|
else:
|
||||||
approved_from = 'Hемає даних про дату запровадження'
|
hours_list = []
|
||||||
event_date = dt.today().strftime('%Y-%m-%d')
|
approved_from = 'Hемає даних про дату запровадження'
|
||||||
|
event_date = dt.today().strftime('%Y-%m-%d')
|
||||||
|
|
||||||
if IS_DEBUG:
|
if IS_DEBUG:
|
||||||
print(f'hours_list{hours_list}, approved_from={approved_from}, event_date={event_date}')
|
print(f'hours_list{hours_list}, approved_from={approved_from}, event_date={event_date}')
|
||||||
|
|
||||||
for h in hours_list:
|
for h in hours_list:
|
||||||
if h["status"] == 1:
|
if h["status"] == 1:
|
||||||
hours_off.append(h["from"])
|
hours_off.append(h["from"])
|
||||||
hours_on.append(h["to"])
|
hours_on.append(h["to"])
|
||||||
|
|
||||||
if IS_DEBUG:
|
if IS_DEBUG:
|
||||||
print(f'hours_off = {hours_off}')
|
print(f'hours_off = {hours_off}')
|
||||||
print(f'hours_on = {hours_on}')
|
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:
|
if IS_DEBUG:
|
||||||
print(f'{message}\nneed_to_send={need_to_send}')
|
print(f'{message}\nneed_to_send={need_to_send}')
|
||||||
|
|
||||||
if need_to_send and not IS_DEBUG:
|
if need_to_send and not IS_DEBUG:
|
||||||
tg_response = send_message_to_tg(message, tg_token, tg_chat)
|
tg_response = send_message_to_tg(message, tg_token, tg_chat)
|
||||||
if tg_response.status_code != 200:
|
if tg_response.status_code != 200:
|
||||||
sys.exit(STATUS_ERROR_SEND_TO_TG)
|
sys.exit(STATUS_ERROR_SEND_TO_TG)
|
||||||
|
|
||||||
if USE_MATRIX:
|
if USE_MATRIX:
|
||||||
res = send_matrix_notification(message)
|
res = send_matrix_notification(message)
|
||||||
if not res:
|
if not res:
|
||||||
sys.exit(STATUS_ERROR_SEND_TO_MX)
|
sys.exit(STATUS_ERROR_SEND_TO_MX)
|
||||||
|
|
||||||
|
|
||||||
def process_PO(apart, house, part_number, settlement, street, tg_chat, tg_token):
|
def process_PO(apart, house, part_number, settlement, street, tg_chat, tg_token):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user