Improve code modularity
This commit is contained in:
parent
88fe86d56a
commit
e91eb187e3
@ -7,8 +7,6 @@ import json
|
||||
import datetime
|
||||
import mongo, helpers
|
||||
|
||||
CORPUS_URL = "https://publicdatafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS"
|
||||
|
||||
#Fetch Configuration
|
||||
CORPUS_USER = os.getenv('OWL_LDB_CORPUSUSER')
|
||||
CORPUS_PASS = os.getenv('OWL_LDB_CORPUSPASS')
|
||||
@ -44,7 +42,7 @@ def isUpdateRequired():
|
||||
|
||||
def fetch():
|
||||
log.out("corpus.fetch: Fetching CORPUS Data from Network Rail", "INFO")
|
||||
response = requests.get(CORPUS_URL, auth=(CORPUS_USER, CORPUS_PASS))
|
||||
response = requests.get(helpers.corpus_data_url, auth=(CORPUS_USER, CORPUS_PASS))
|
||||
mongo.incrementCounter("corpus_api")
|
||||
log.out("corpus.fetch: Decompressing & parsing CORPUS data", "INFO")
|
||||
parsed = json.loads(zlib.decompress(response.content, 16+zlib.MAX_WBITS).decode())
|
||||
|
@ -1,7 +1,24 @@
|
||||
import time
|
||||
import time, os
|
||||
|
||||
## Environment Options
|
||||
env_corpus_user = os.getenv('OWL_LDB_CORPUSUSER')
|
||||
env_corpus_pass = os.getenv('OWL_LDB_CORPUSPASS')
|
||||
|
||||
## Timetable Data Options
|
||||
required_toc_codes = ["EF"]
|
||||
|
||||
## PIS Data Options
|
||||
pis_file_paths = [
|
||||
"/app/data/pis/gwr.yaml"
|
||||
]
|
||||
|
||||
## Upstream Data URLs
|
||||
corpus_data_url = "https://publicdatafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS"
|
||||
|
||||
## Time Constants
|
||||
one_day_in_seconds = 84600
|
||||
two_weeks_in_seconds = 1209600
|
||||
two_day_in_seconds = one_day_in_seconds * 2
|
||||
two_weeks_in_seconds = one_day_in_seconds * 14
|
||||
|
||||
def getAgeInSeconds(updateTimeInSeconds :int):
|
||||
now = int(time.time())
|
||||
|
@ -32,8 +32,6 @@ now = datetime.now()
|
||||
yesterday = now - timedelta(days=1)
|
||||
yesterdayDay = yesterday.strftime("%a").lower()
|
||||
todayDay = now.strftime("%a").lower()
|
||||
oneDayinSecs = 86400
|
||||
twoDayinSecs = 86400 * 2
|
||||
isAfter0800 = (int(now.strftime("%H")) >= 8)
|
||||
filePath = "cif_data"
|
||||
TOC_Code = "EF" # Business code for GWR
|
||||
@ -52,10 +50,10 @@ def isUpdateRequired():
|
||||
timetableDataAge = helpers.getAgeInSeconds(timetableUpdateTime)
|
||||
readable_age = str(timedelta(seconds=timetableDataAge))
|
||||
log.out(f"timetable.isUpdateRequired: Timetable data age: {readable_age}", "INFO")
|
||||
if (timetableDataAge >= twoDayinSecs and isAfter0800) or REBUILD:
|
||||
if (timetableDataAge >= helpers.two_day_in_seconds and isAfter0800) or REBUILD:
|
||||
log.out(f"timetable.isUpdateRequired: timetable collection requires rebuild", "INFO")
|
||||
return "full"
|
||||
if (timetableDataAge >= oneDayinSecs and isAfter0800):
|
||||
if (timetableDataAge >= helpers.one_day_in_seconds and isAfter0800):
|
||||
log.out(f"timetable.isUpdateRequired: timetable collection requires update", "INFO")
|
||||
return "update"
|
||||
return False
|
||||
|
Reference in New Issue
Block a user