Improved informer
This commit is contained in:
parent
bfed31c890
commit
108ba70991
29
get_eo.py
29
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))
|
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=''):
|
def save_last_datas_PO(placed='', star_dt='', start_tm='', stop_dt='', stop_tm=''):
|
||||||
date = dt.today().strftime('%Y-%m-%d')
|
date = dt.today().strftime('%Y-%m-%d')
|
||||||
with open(LAST_DATAS_FILE_NAME_PO, 'w') as f:
|
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
|
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=''):
|
def is_old_and_new_datas_equals_PO(placed='', star_dt='', start_tm='', stop_dt='', stop_tm=''):
|
||||||
date = dt.today().strftime('%Y-%m-%d')
|
date = dt.today().strftime('%Y-%m-%d')
|
||||||
loaded = load_last_datas(LAST_DATAS_FILE_NAME_PO)
|
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
|
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):
|
def get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue):
|
||||||
queue = get_utf_chars(outage_queue)
|
queue = get_utf_chars(outage_queue)
|
||||||
message = f'\U000026A1 <b>ГПВ на {event_date} для {queue} черги</b>'
|
message = f'\U000026A1 <b>ГПВ на {event_date} для {queue} черги</b>'
|
||||||
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:
|
if len(hours_off) > 0:
|
||||||
message += '\nВимкнення:'
|
message += '\nВимкнення:'
|
||||||
@ -233,7 +244,7 @@ def get_GPV_message(approved_from, event_date, hours_off, hours_on, outage_queue
|
|||||||
else:
|
else:
|
||||||
message += '\nВимкнень немає \U0001F44C \U0001F483'
|
message += '\nВимкнень немає \U0001F44C \U0001F483'
|
||||||
message += (f'\n<b><i>{approved_from}</i></b>')
|
message += (f'\n<b><i>{approved_from}</i></b>')
|
||||||
return message, need_to_send
|
return message
|
||||||
|
|
||||||
|
|
||||||
def get_address(city, street, house):
|
def get_address(city, street, house):
|
||||||
@ -383,8 +394,6 @@ def process_GPV(oe_account_number, tg_chat, tg_token):
|
|||||||
|
|
||||||
x = response.json()
|
x = response.json()
|
||||||
|
|
||||||
hours_off = []
|
|
||||||
hours_on = []
|
|
||||||
outage_queue = str(x["current"]["queue"])
|
outage_queue = str(x["current"]["queue"])
|
||||||
if x["current"]["subQueue"]:
|
if x["current"]["subQueue"]:
|
||||||
outage_queue += '.' + str(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"]):
|
if 'queues' in str(x["schedule"]):
|
||||||
datas = sorted(x["schedule"], key=lambda item: item['eventDate'])
|
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:
|
for entry in datas:
|
||||||
|
hours_off = []
|
||||||
|
hours_on = []
|
||||||
if len(entry) > 0:
|
if len(entry) > 0:
|
||||||
approved_from = 'Запроваджено ' + entry['scheduleApprovedSince']
|
approved_from = 'Запроваджено ' + entry['scheduleApprovedSince']
|
||||||
event_date = entry['eventDate']
|
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_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 = 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}')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user