diff --git a/mftp/notice.py b/mftp/notice.py index b0d6c01..1e469a7 100644 --- a/mftp/notice.py +++ b/mftp/notice.py @@ -34,13 +34,17 @@ def fetch(headers, session, ssoToken, lsnif): 'Subject': row.find('cell[3]').text.strip(), 'Company': row.find('cell[4]').text.strip(), } + + if int(id_) < latest_index: + logging.info(f' [NEW SESSION DETECTED] Requesting {lsnif} reset') + latest_index = 0 if int(id_) > latest_index: notices.append(notice) logging.info(f" [NEW NOTICE]: #{id_} | {notice['Type']} | {notice['Subject']} | {notice['Company']} | {notice['Time']}") else: break - + return notices @@ -71,12 +75,15 @@ def update_lsni(lsnif, notices, i): def has_idx_mutated(lsnif, notices, i): - lidx_from_file = get_latest_index(lsnif) # Latest Index from File cidx_from_to_send_notifs = int(notices[-i]['UID'].split('_')[0]) # Current Index from to send notifications - difference_in_idx = cidx_from_to_send_notifs - lidx_from_file + if cidx_from_to_send_notifs == 1: + logging.info(f' [NEW SESSION DETECTED] Approving {lsnif} reset') + return False + lidx_from_file = get_latest_index(lsnif) # Latest Index from File + difference_in_idx = cidx_from_to_send_notifs - lidx_from_file if difference_in_idx != 1: - logging.error(f' Trying to send mail #{cidx_from_to_send_notifs} while latest in database is #{lidx_from_file}') + logging.error(f' Trying to send notif #{cidx_from_to_send_notifs} while latest in database is #{lidx_from_file}') return True return False diff --git a/mftp/ntfy.py b/mftp/ntfy.py index d06190f..38f034d 100644 --- a/mftp/ntfy.py +++ b/mftp/ntfy.py @@ -70,7 +70,7 @@ def format_notice(notices, session): try: attachment = parseAttachment(session, year, id_) except Exception as e: - logging.error(f" Failed to parse mail attachment ~ {str(e)}") + logging.error(f" Failed to parse attachment ~ {str(e)}") if len(attachment) != 0: file_name = notification['Attachment']