diff --git a/src/reasonCodes.py b/src/reasonCodes.py index f7c202a..86e3b4c 100644 --- a/src/reasonCodes.py +++ b/src/reasonCodes.py @@ -1,4 +1,4 @@ -import json, hashlib +import json, hashlib, urllib.request import mongo import logger as log @@ -6,10 +6,13 @@ REBUILD = False log.out("reasonCodes.py: reasonCodes module initialised", "DBUG") -file_location :str = "/app/data/reasonCodes/reasoncodes.json" # Production & Testing -#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/reasonCodes/reasoncodes.json" # Local Development +file_location :str = "reasoncodes.json" +file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/reasonCodes/reasoncodes.json" def runUpdate(): + state = download() + if (not state): + log.out("reasonCodes.runUpdate: Unable to update reason codes") if (not requiresUpdate()): log.out('reasonCodes.runUpdate: Reason codes do not need updating', 'INFO') return @@ -19,6 +22,15 @@ def runUpdate(): mongo.dropCollection("reasonCodes") 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(): if REBUILD: return True