diff --git a/get_eo.py b/get_eo.py
index 95c3b69..2094c81 100644
--- a/get_eo.py
+++ b/get_eo.py
@@ -186,6 +186,11 @@ def save_last_datas_GPV(hours_on, hours_off, date, day):
f.write(LAST_DATAS_FORMAT_GPV.format(array=str(hours_on) + str(hours_off), date=date, day=day))
+def save_last_datas_GPV(datas):
+ with open(LAST_DATAS_FILE_NAME_GPV, 'w') as f:
+ f.write(str(datas))
+
+
def save_last_datas_PO(placed='', star_dt='', start_tm='', stop_dt='', stop_tm=''):
date = dt.today().strftime('%Y-%m-%d')
with open(LAST_DATAS_FILE_NAME_PO, 'w') as f:
@@ -207,6 +212,10 @@ def is_old_and_new_datas_equals_GPV(hours_on, hours_off, date, day):
return LAST_DATAS_FORMAT_GPV.format(array=str(hours_on) + str(hours_off), date=date, day=day) == loaded
+def is_old_and_new_datas_equals_GPV(datas):
+ loaded = load_last_datas(LAST_DATAS_FILE_NAME_GPV)
+ return str(datas) == str(loaded)
+
def is_old_and_new_datas_equals_PO(placed='', star_dt='', start_tm='', stop_dt='', stop_tm=''):
date = dt.today().strftime('%Y-%m-%d')
loaded = load_last_datas(LAST_DATAS_FILE_NAME_PO)
@@ -215,12 +224,14 @@ def is_old_and_new_datas_equals_PO(placed='', star_dt='', start_tm='', stop_dt='
stop_tm=str(stop_tm), current_date=date) == loaded
+def is_need_toSend(approved_from, event_date, hours_off, hours_on):
+ need_to_send = not is_old_and_new_datas_equals_GPV(hours_off, hours_on, approved_from, event_date)
+ return need_to_send
+
+
def get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue):
queue = get_utf_chars(outage_queue)
message = f'\U000026A1 ГПВ на {event_date} для {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Вимкнення:'
@@ -233,7 +244,7 @@ def get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue
else:
message += '\nВимкнень немає \U0001F44C \U0001F483'
message += (f'\n{approved_from}')
- return message, need_to_send
+ return message
def get_address(city, street, house):
@@ -383,8 +394,6 @@ def process_GPV(oe_account_number, tg_chat, tg_token):
x = response.json()
- hours_off = []
- hours_on = []
outage_queue = str(x["current"]["queue"])
if x["current"]["subQueue"]:
outage_queue += '.' + str(x["current"]["subQueue"])
@@ -393,7 +402,13 @@ def process_GPV(oe_account_number, tg_chat, tg_token):
if 'queues' in str(x["schedule"]):
datas = sorted(x["schedule"], key=lambda item: item['eventDate'])
+ need_to_send = not is_old_and_new_datas_equals_GPV(datas)
+ if need_to_send:
+ save_last_datas_GPV(datas)
+
for entry in datas:
+ hours_off = []
+ hours_on = []
if len(entry) > 0:
approved_from = 'Запроваджено ' + entry['scheduleApprovedSince']
event_date = entry['eventDate']
@@ -415,7 +430,7 @@ def process_GPV(oe_account_number, tg_chat, tg_token):
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 = 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}')