Compare commits

..

2 Commits

5 changed files with 40 additions and 2329 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -41,18 +41,19 @@ def fetchLogs():
with open("dbman-log", "r") as tmpfile: with open("dbman-log", "r") as tmpfile:
return tmpfile.read() return tmpfile.read()
def deleteLogs(): def tidyWorkingFiles():
if os.path.exists("dbman-log"): if os.path.exists("dbman-log"):
os.remove("dbman-log") os.remove("dbman-log")
print("Tidied log file") print("Tidied log file")
else:
print("No logfile to tidy")
if os.path.exists("cif_data"): if os.path.exists("cif_data"):
os.remove("cif_data") os.remove("cif_data")
print("Removed cif_data file") print("Removed cif_data file")
else: if os.path.exists("gw.yaml"):
print("No cif_data to tidy") os.remove("gw.yaml")
print("Tidied PIS Data")
if os.path.exists("reasoncodes.json"):
os.remove("reasoncodes.json")
print("Tidies reason code data")
def sendMail(msg_body :str, retry): def sendMail(msg_body :str, retry):
message = MIMEMultipart() message = MIMEMultipart()
@ -88,4 +89,4 @@ def sendMail(msg_body :str, retry):
else: else:
print("Error retrying to mail logs, giving up") print("Error retrying to mail logs, giving up")
finally: finally:
deleteLogs() tidyWorkingFiles()

View File

@ -1,14 +1,20 @@
import yaml, hashlib import yaml, hashlib, urllib.request
import logger as log import logger as log
import mongo import mongo
REBUILD :bool = False # Set to True to force rebuild REBUILD :bool = False # Set to True to force rebuild
log.out("pis.py: PIS Module Loaded", "DBUG") log.out("pis.py: PIS Module Loaded", "DBUG")
file_location :str = "/app/data/pis/gwr.yaml" # Production & Testing #file_location :str = "/app/data/pis/gwr.yaml" # Production & Testing
#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/pis/gwr.yaml" # Local Development #file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/pis/gwr.yaml" # Local Development
file_location :str = "gw.yaml"
file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/pis/gw.yaml"
def runUpdate(): def runUpdate():
state = download()
if (not state):
log.out('pis.runUpdate: Not updating PIS, unable to download data')
return
if (not requiresUpdate()): if (not requiresUpdate()):
log.out('pis.runUpdate: PIS Codes do not need updating', 'INFO') log.out('pis.runUpdate: PIS Codes do not need updating', 'INFO')
return return
@ -35,6 +41,15 @@ def requiresUpdate():
log.out("pis.requiredUpdate: PIS Data is up to date", "INFO") log.out("pis.requiredUpdate: PIS Data is up to date", "INFO")
return False return False
def download():
log.out("pis.download: Downloading GW PIS file")
try:
urllib.request.urlretrieve(file_url, file_location)
return True
except Exception as e:
log.out(f"pis.download: Download error: {e}")
return False
def load(): def load():
with open(file_location, "r") as data: with open(file_location, "r") as data:
try: try:

View File

@ -1,4 +1,4 @@
import json, hashlib import json, hashlib, urllib.request
import mongo import mongo
import logger as log import logger as log
@ -6,10 +6,13 @@ REBUILD = False
log.out("reasonCodes.py: reasonCodes module initialised", "DBUG") log.out("reasonCodes.py: reasonCodes module initialised", "DBUG")
file_location :str = "/app/data/reasonCodes/reasoncodes.json" # Production & Testing file_location :str = "reasoncodes.json"
#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/reasonCodes/reasoncodes.json" # Local Development file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/reasonCodes/reasoncodes.json"
def runUpdate(): def runUpdate():
state = download()
if (not state):
log.out("reasonCodes.runUpdate: Unable to update reason codes")
if (not requiresUpdate()): if (not requiresUpdate()):
log.out('reasonCodes.runUpdate: Reason codes do not need updating', 'INFO') log.out('reasonCodes.runUpdate: Reason codes do not need updating', 'INFO')
return return
@ -19,6 +22,15 @@ def runUpdate():
mongo.dropCollection("reasonCodes") mongo.dropCollection("reasonCodes")
mongo.putMany("reasonCodes", reason_code_data, reason_code_indexes) mongo.putMany("reasonCodes", reason_code_data, reason_code_indexes)
def download():
log.out("pis.download: Downloading reason codes file")
try:
urllib.request.urlretrieve(file_url, file_location)
return True
except Exception as e:
log.out(f"pis.download: Download error: {e}")
return False
def requiresUpdate(): def requiresUpdate():
if REBUILD: if REBUILD:
return True return True