Add reasoncode data
This commit is contained in:
parent
5964b537bc
commit
17455c9e80
1
data/reasonCodes/reasoncodes.json
Normal file
1
data/reasonCodes/reasoncodes.json
Normal file
File diff suppressed because one or more lines are too long
@ -14,7 +14,7 @@
|
||||
# program. If not, see
|
||||
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
|
||||
|
||||
version = "2023.6.10"
|
||||
version = "2023.6.11"
|
||||
print(f"main.py: Initialising db-manager v{version}")
|
||||
|
||||
#Third Party Imports
|
||||
@ -26,7 +26,7 @@ import logger as log
|
||||
log.out(f"main.py: db-manager {version} Initialised on host {os.uname()[1]}", "INFO")
|
||||
|
||||
#Local Imports
|
||||
import corpus, mongo, pis, mailer, timetable
|
||||
import corpus, mongo, pis, mailer, timetable, reasonCodes
|
||||
|
||||
# Ensure count document exists in meta, wrap in while look to prevent crashing if the DB is not ready:
|
||||
# Does this work when the DB is not initialised?
|
||||
@ -44,6 +44,9 @@ status = corpus.runUpdate()
|
||||
## Run PIS Update
|
||||
pis.runUpdate()
|
||||
|
||||
## Run reasonCodes update
|
||||
reasonCodes.runUpdate()
|
||||
|
||||
## Run Timetable Update
|
||||
timetable.runUpdate()
|
||||
|
||||
|
@ -111,7 +111,6 @@ def getMetaHash(target):
|
||||
if type(res) is dict:
|
||||
if 'updated' in res:
|
||||
try:
|
||||
log.out(f'mongo.metaGetHash: {target} hash is {res["hash"]}', 'INFO')
|
||||
return res["hash"]
|
||||
except:
|
||||
return None
|
||||
|
@ -6,7 +6,7 @@ REBUILD :bool = False # Set to True to force rebuild
|
||||
|
||||
log.out("pis.py: PIS Module Loaded", "DBUG")
|
||||
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
|
||||
|
||||
def runUpdate():
|
||||
if (not requiresUpdate()):
|
||||
|
46
src/reasonCodes.py
Normal file
46
src/reasonCodes.py
Normal file
@ -0,0 +1,46 @@
|
||||
import json, hashlib
|
||||
import mongo
|
||||
import logger as log
|
||||
|
||||
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
|
||||
|
||||
def runUpdate():
|
||||
if (not requiresUpdate()):
|
||||
log.out('reasonCodes.runUpdate: Reason codes do not need updating', 'INFO')
|
||||
return
|
||||
log.out(f"reasonCodes.runUpdate: Update required", "INFO")
|
||||
reason_code_data = load()
|
||||
reason_code_indexes = ["code"]
|
||||
mongo.dropCollection("reasonCodes")
|
||||
mongo.putMany("reasonCodes", reason_code_data, reason_code_indexes)
|
||||
|
||||
def requiresUpdate():
|
||||
if REBUILD:
|
||||
return True
|
||||
current_hash = mongo.getMetaHash("reasonCodes")
|
||||
with open(file_location, "r") as f:
|
||||
text = f.read()
|
||||
newHash = hashlib.md5(text.encode()).hexdigest()
|
||||
log.out(f"reasonCodes.requiresUpdate: Database Hash: {current_hash}","INFO")
|
||||
log.out(f"reasonCodes.requiresUpdate: File hash: {newHash}", "INFO")
|
||||
if current_hash is None or newHash != current_hash:
|
||||
log.out("reasonCodes.requiredUpdate: reasonCodes require updating", "INFO")
|
||||
mongo.putMetaHash("reasonCodes", newHash)
|
||||
return True
|
||||
log.out("reasonCodes.requiredUpdate: reasonCodes are up to date", "INFO")
|
||||
return False
|
||||
|
||||
def load():
|
||||
with open(file_location, "r") as data:
|
||||
try:
|
||||
json_data = data.read()
|
||||
reason_code = json.loads(json_data)
|
||||
return reason_code['GetReasonCodeListResult']['reason']
|
||||
except Exception as exc:
|
||||
log.out(f"reasonCodes.load: {exc}", "EROR")
|
||||
return exc
|
Reference in New Issue
Block a user