This commit is contained in:
Fred Boniface 2023-06-04 23:28:50 +01:00
parent 9232c740a0
commit 1588f3c86c
3 changed files with 16 additions and 9 deletions

View File

@ -30,9 +30,11 @@ smtpFrom = os.getenv("OWL_EML_FROM")
log.out("mailer.py: Mailer module loaded", "DBUG") log.out("mailer.py: Mailer module loaded", "DBUG")
def submitLogs(): def submitLogs(retry :bool = False):
if retry:
log.out("mailer.submitLogs: Retrying fetch and send")
text :str = fetchLogs() text :str = fetchLogs()
sendMail(text) sendMail(text, retry)
def fetchLogs(): def fetchLogs():
with open("dbman-log", "r") as tmpfile: with open("dbman-log", "r") as tmpfile:
@ -46,7 +48,7 @@ def deleteLogs():
print("No logfile to tidy") print("No logfile to tidy")
def sendMail(msg_body :str): def sendMail(msg_body :str, retry):
message = MIMEMultipart() message = MIMEMultipart()
message['From'] = smtpFrom message['From'] = smtpFrom
message['To'] = "server-notification-receipt@fjla.uk" message['To'] = "server-notification-receipt@fjla.uk"
@ -71,6 +73,12 @@ def sendMail(msg_body :str):
server.login(smtpUser, smtpPass) server.login(smtpUser, smtpPass)
server.sendmail(smtpFrom, "server-notification-receipt@fjla.uk", text) server.sendmail(smtpFrom, "server-notification-receipt@fjla.uk", text)
except Exception as e: except Exception as e:
print("mailer.sendMail: Error sending message", e) log.out(f"mailer.sendMail: Error sending message: {e}", "EROR")
if not retry:
os.remove("cif_data")
log.out("mailer.sendMail: Removing CIF Data to shrink email size")
submitLogs(retry = True)
else:
print("Error retrying to mail logs, giving up")
finally: finally:
deleteLogs() deleteLogs()

View File

@ -14,7 +14,7 @@
# program. If not, see # program. If not, see
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE # https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
version = "2023.6.4" version = "2023.6.5"
print(f"main.py: Initialising db-manager v{version}") print(f"main.py: Initialising db-manager v{version}")
#Third Party Imports #Third Party Imports

View File

@ -37,7 +37,6 @@ def load(): # Programatically add a `toc` field to each entry.
with open(file_location, "r") as data: with open(file_location, "r") as data:
try: try:
pis = yaml.safe_load(data) pis = yaml.safe_load(data)
#print(pis)
return pis["pis"] return pis["pis"]
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
@ -53,7 +52,7 @@ def parse(codeList):
code = i['code'] code = i['code']
for ii in codeList: for ii in codeList:
if stops == ii['stops'] and code != ii['code']: if stops == ii['stops'] and code != ii['code']:
print(f"Identical stopping pattern found: {ii['code']}") log.out(f"Identical stopping pattern found: {ii['code']}","DBUG")
codeList.remove(ii) # Instead of removing, I should add a property (duplicate: true), then I can filter this out on the backend when searching by start and end stations and just use query one for other queries, this means that when searching by code, a perfectly valid code won't show 0 results. codeList.remove(ii) # Instead of removing, I should add a property (duplicate: true), then I can filter this out on the backend when searching by start and end stations and just use query one for other queries, this means that when searching by code, a perfectly valid code won't show 0 results.
tiplocs = [] tiplocs = []
for iii in stops: for iii in stops:
@ -75,5 +74,5 @@ def getTiploc(crs :str):
if 'TIPLOC' in res: if 'TIPLOC' in res:
return res['TIPLOC'] return res['TIPLOC']
except Exception as e: except Exception as e:
log.out("pis.getTiploc: Error finding tiploc:", query) log.out(f"pis.getTiploc: Error finding tiploc: {query}", "EROR")
print("ERROR", e) log.out(f"ERROR: {e}", "EROR")