47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
|
#!/usr/bin/env python3
|
||
|
"""
|
||
|
If daily processing crashed, files will be in
|
||
|
2 directories, trigger an email if a file is left over
|
||
|
"""
|
||
|
import pprint
|
||
|
import pathlib
|
||
|
import smtplib
|
||
|
from email.mime.multipart import MIMEMultipart
|
||
|
from email.mime.text import MIMEText
|
||
|
|
||
|
THIS_DIRECTORY = pathlib.Path(__file__).parent
|
||
|
|
||
|
INCOMING_DIRECTORY = THIS_DIRECTORY / "incoming_orders"
|
||
|
SHIPMENTS_DIRECTORY = THIS_DIRECTORY / "incoming_shipments"
|
||
|
SOH_IMPORT_DIRECTORY = THIS_DIRECTORY / "to_import_SOH"
|
||
|
|
||
|
def main():
|
||
|
#retrieve_x12_edi_files()#TODO remove this as it's handled by the earlier process
|
||
|
file_count = []
|
||
|
for file in INCOMING_DIRECTORY.iterdir():
|
||
|
if file.name[-4:] == '.csv':
|
||
|
file_count.append(file.name)
|
||
|
for file in SHIPMENTS_DIRECTORY.iterdir():
|
||
|
if file.name[-4:] == '.csv':
|
||
|
file_count.append(file.name)
|
||
|
if file_count:
|
||
|
file_alert(file_count)
|
||
|
|
||
|
def file_alert(file_list):
|
||
|
file_string = ', '.join(file_list)
|
||
|
msg = MIMEMultipart()
|
||
|
msg['Subject'] = 'Source ecommerce: Files Left Over'
|
||
|
msg['Precedence'] = 'bulk'
|
||
|
msg['From'] = 'x3report@stashtea.com'
|
||
|
msg['To'] = 'bleeson@stashtea.com'
|
||
|
#msg['CC'] = 'bleeson@stashtea.com'
|
||
|
emailtext = f'files: {file_string}'
|
||
|
msg.attach(MIMEText(emailtext, 'plain'))
|
||
|
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
|
||
|
smtp.login(user='x3reportmk2@yamamotoyama.com', password=r'n</W<7fr"VD~\2&[pZc5')
|
||
|
smtp.send_message(msg)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|