From 831cefb2d7f591ada98166f8824935bd27489f42 Mon Sep 17 00:00:00 2001 From: bleeson Date: Fri, 13 Jun 2025 08:50:10 -0700 Subject: [PATCH] Added leftover file alerts, removed comments from 944s, leftover function added to master_controller --- edi_944_to_table.py | 6 +++--- leftover_file_alerts.py | 36 ++++++++++++++++++++++++++++++++++++ master_contoller.py | 4 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 leftover_file_alerts.py diff --git a/edi_944_to_table.py b/edi_944_to_table.py index 26e7080..f05ea28 100644 --- a/edi_944_to_table.py +++ b/edi_944_to_table.py @@ -77,7 +77,7 @@ def main(): if SHANDEX_944_FILENAME_RE.match(edi_filename.name): determine_edi_action(edi_filename) # file moved to 997 processing folder to be sent later - # shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name)#TODO uncomment + shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name) def determine_edi_action(edi_filename: pathlib.Path): @@ -90,7 +90,7 @@ def determine_edi_action(edi_filename: pathlib.Path): transaction = '' for fields in tokens_from_edi_file(edi_filename): if fields[0] == "W17": - transaction = fields[4] + transaction = fields[5] break pprint.pprint(transaction) if transaction: @@ -252,7 +252,7 @@ def process_intersite_receipt(edi_filename: pathlib.Path): subdetail, ) time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") - #import_receipt(warehouse_receipt)#TODO uncomment + import_receipt(warehouse_receipt) def import_receipt(warehouse_receipt): diff --git a/leftover_file_alerts.py b/leftover_file_alerts.py new file mode 100644 index 0000000..9b17e7f --- /dev/null +++ b/leftover_file_alerts.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +""" +Shandex version, check for unprocessed EDI files and alert +that there is a problem of some kind, all files should move out of +these folders for each run of master controller +""" +import pprint +import pathlib +import simple_email_notification + +#The directories we want to check for a leftover file +THIS_DIRECTORY = pathlib.Path(__file__).parent +OUTGOING_DIRECTORY = THIS_DIRECTORY / 'outgoing' +INCOMING_DIRECTORY = THIS_DIRECTORY / 'incoming' + +MONITOR_LIST = [OUTGOING_DIRECTORY, INCOMING_DIRECTORY] + +def main(): + """ + Check for leftover files which means something unexpected happened. + """ + file_count = [] + for path in MONITOR_LIST: + for file in path.iterdir(): + if file.name[-4:] == '.edi' or file.name[-4:] == '.txt': + file_count.append(f'{path}\\{file.name}') + if file_count: + simple_email_notification.email_noticication( + ['bleeson@stashtea.com','icarrera@yamamotoyama.com'], + 'Shandex EDI leftover files', + file_count + ) + + +if __name__ == "__main__": + main() diff --git a/master_contoller.py b/master_contoller.py index 337ad46..48c9b43 100644 --- a/master_contoller.py +++ b/master_contoller.py @@ -16,10 +16,10 @@ import edi_867_to_table import edi_997_outbound import update_shandex_dashboard import edi_943 -import unprocessed_files_report import import_867s import import_944s import edi_850 +import leftover_file_alerts THIS_DIRECTORY = pathlib.Path(__file__).parent X12_SHANDEX_OUTGOING = THIS_DIRECTORY / "outgoing" @@ -58,7 +58,7 @@ def main(): #update_shandex_dashboard.main() #report on anything not handled - #unprocessed_files_report.main() + leftover_file_alerts.main()