Compare commits

..

2 Commits

2 changed files with 8 additions and 7 deletions

View File

@ -88,6 +88,8 @@ def putVersion(version):
return return
def putTimetable(data): def putTimetable(data):
data_length = len(data)
log.out(f"mongo.putTimetable: Adding {data_length} documents to the database")
collection = "timetable" collection = "timetable"
col = db[collection] col = db[collection]
res = col.insert_many(data) res = col.insert_many(data)

View File

@ -34,9 +34,8 @@ yesterdayDay = yesterday.strftime("%a").lower()
todayDay = now.strftime("%a").lower() todayDay = now.strftime("%a").lower()
isAfter0800 = (int(now.strftime("%H")) >= 8) isAfter0800 = (int(now.strftime("%H")) >= 8)
filePath = "cif_data" filePath = "cif_data"
TOC_Code = "EF" # Business code for GWR fullDataUrl = "https://publicdatafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_ALL_FULL_DAILY&day=toc-full"
fullDataUrl = f"https://publicdatafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_{TOC_Code}_TOC_FULL_DAILY&day=toc-full" updateDataUrl = f"https://publicdatafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_ALL_FULL_DAILY&day=toc-update-{yesterdayDay}"
updateDataUrl = f"https://publicdatafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_{TOC_Code}_TOC_UPDATE_DAILY&day=toc-update-{yesterdayDay}"
CORPUS_USER = os.getenv('OWL_LDB_CORPUSUSER') CORPUS_USER = os.getenv('OWL_LDB_CORPUSUSER')
CORPUS_PASS = os.getenv('OWL_LDB_CORPUSPASS') CORPUS_PASS = os.getenv('OWL_LDB_CORPUSPASS')
@ -106,7 +105,6 @@ def runUpdate():
if (status): if (status):
mongo.metaUpdateTime("timetable") mongo.metaUpdateTime("timetable")
_removeOutdatedServices() _removeOutdatedServices()
## Check what happens if there is no update
def insertSchedule(sch_record): def insertSchedule(sch_record):
schedule = sch_record['JsonScheduleV1'] schedule = sch_record['JsonScheduleV1']
@ -148,12 +146,13 @@ def _insertToDb(data :list, type :str):
mongo.putTimetable(data) mongo.putTimetable(data)
mongo.createSingleIndex("timetable", "headcode") mongo.createSingleIndex("timetable", "headcode")
elif type == "update": elif type == "update":
create_transactions = []
for item in data: for item in data:
if item['transactionType'] == "Create": if item['transactionType'] == "Create":
singleList = [item] ### These items should be stored in a list and only create_transactions.append([item])
mongo.putTimetable(singleList) ### Put into the databse AFTER deletions.
elif item['transactionType'] == "Delete": elif item['transactionType'] == "Delete":
mongo.deleteTimetableData({'trainUid': item['trainUid'], 'scheduleStartDate': item['scheduleStartDate'], 'stpIndicator': item['stpIndicator']}) ## Also need to consider the STP indicator and end date here else I am deleting LTP services when an STP is meant to be deleted. mongo.deleteTimetableData({'trainUid': item['trainUid'], 'scheduleStartDate': item['scheduleStartDate'], 'stpIndicator': item['stpIndicator']})
mongo.putTimetable(create_transactions)
post_count = mongo.getLength("timetable") post_count = mongo.getLength("timetable")
log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG") log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG")
return True #If Successfuls return True #If Successfuls