Compare commits
No commits in common. "bc62408313bf369e137682905f487837662bc374" and "e4a275bae34644b141e358af64d619b581bb6dac" have entirely different histories.
bc62408313
...
e4a275bae3
2316
data/pis/gwr.yaml
Normal file
2316
data/pis/gwr.yaml
Normal file
File diff suppressed because it is too large
Load Diff
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
@ -41,19 +41,18 @@ def fetchLogs():
|
||||
with open("dbman-log", "r") as tmpfile:
|
||||
return tmpfile.read()
|
||||
|
||||
def tidyWorkingFiles():
|
||||
def deleteLogs():
|
||||
if os.path.exists("dbman-log"):
|
||||
os.remove("dbman-log")
|
||||
print("Tidied log file")
|
||||
else:
|
||||
print("No logfile to tidy")
|
||||
if os.path.exists("cif_data"):
|
||||
os.remove("cif_data")
|
||||
print("Removed cif_data file")
|
||||
if os.path.exists("gw.yaml"):
|
||||
os.remove("gw.yaml")
|
||||
print("Tidied PIS Data")
|
||||
if os.path.exists("reasoncodes.json"):
|
||||
os.remove("reasoncodes.json")
|
||||
print("Tidies reason code data")
|
||||
else:
|
||||
print("No cif_data to tidy")
|
||||
|
||||
|
||||
def sendMail(msg_body :str, retry):
|
||||
message = MIMEMultipart()
|
||||
@ -89,4 +88,4 @@ def sendMail(msg_body :str, retry):
|
||||
else:
|
||||
print("Error retrying to mail logs, giving up")
|
||||
finally:
|
||||
tidyWorkingFiles()
|
||||
deleteLogs()
|
||||
19
src/pis.py
19
src/pis.py
@ -1,20 +1,14 @@
|
||||
import yaml, hashlib, urllib.request
|
||||
import yaml, hashlib
|
||||
import logger as log
|
||||
import mongo
|
||||
|
||||
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 = "/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 = "gw.yaml"
|
||||
file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/pis/gw.yaml"
|
||||
|
||||
def runUpdate():
|
||||
state = download()
|
||||
if (not state):
|
||||
log.out('pis.runUpdate: Not updating PIS, unable to download data')
|
||||
return
|
||||
if (not requiresUpdate()):
|
||||
log.out('pis.runUpdate: PIS Codes do not need updating', 'INFO')
|
||||
return
|
||||
@ -41,15 +35,6 @@ def requiresUpdate():
|
||||
log.out("pis.requiredUpdate: PIS Data is up to date", "INFO")
|
||||
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():
|
||||
with open(file_location, "r") as data:
|
||||
try:
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import json, hashlib, urllib.request
|
||||
import json, hashlib
|
||||
import mongo
|
||||
import logger as log
|
||||
|
||||
@ -6,13 +6,10 @@ REBUILD = False
|
||||
|
||||
log.out("reasonCodes.py: reasonCodes module initialised", "DBUG")
|
||||
|
||||
file_location :str = "reasoncodes.json"
|
||||
file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/reasonCodes/reasoncodes.json"
|
||||
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():
|
||||
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
|
||||
@ -22,15 +19,6 @@ 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