Remove data from the container image and access via HTTP
This commit is contained in:
parent
e4a275bae3
commit
9491be73b9
@ -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
|
||||
|
Reference in New Issue
Block a user