Compare commits
No commits in common. "bc62408313bf369e137682905f487837662bc374" and "e4a275bae34644b141e358af64d619b581bb6dac" have entirely different histories.
bc62408313
...
e4a275bae3
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -41,19 +41,18 @@ def fetchLogs():
|
||||||
with open("dbman-log", "r") as tmpfile:
|
with open("dbman-log", "r") as tmpfile:
|
||||||
return tmpfile.read()
|
return tmpfile.read()
|
||||||
|
|
||||||
def tidyWorkingFiles():
|
def deleteLogs():
|
||||||
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")
|
||||||
if os.path.exists("gw.yaml"):
|
else:
|
||||||
os.remove("gw.yaml")
|
print("No cif_data to tidy")
|
||||||
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()
|
||||||
|
@ -89,4 +88,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:
|
||||||
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 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
|
||||||
|
@ -41,15 +35,6 @@ 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:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, hashlib, urllib.request
|
import json, hashlib
|
||||||
import mongo
|
import mongo
|
||||||
import logger as log
|
import logger as log
|
||||||
|
|
||||||
|
@ -6,13 +6,10 @@ REBUILD = False
|
||||||
|
|
||||||
log.out("reasonCodes.py: reasonCodes module initialised", "DBUG")
|
log.out("reasonCodes.py: reasonCodes module initialised", "DBUG")
|
||||||
|
|
||||||
file_location :str = "reasoncodes.json"
|
file_location :str = "/app/data/reasonCodes/reasoncodes.json" # Production & Testing
|
||||||
file_url :str = "https://git.fjla.uk/OwlBoard/data/raw/branch/main/reasonCodes/reasoncodes.json"
|
#file_location :str = "/home/fred.boniface/git/owlboard/db-manager/data/reasonCodes/reasoncodes.json" # Local Development
|
||||||
|
|
||||||
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
|
||||||
|
@ -22,15 +19,6 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue