Fix timetable update handling
This commit is contained in:
parent
3fe1e13d9b
commit
ec83af3a3a
@ -152,6 +152,7 @@ def dropCollection(collection):
|
||||
def deleteTimetableData(query):
|
||||
collection = "timetable"
|
||||
col = db[collection]
|
||||
log.out(f"mongo.deleteTimetableData: Deleting entry matching {query}")
|
||||
res = col.delete_one(query)
|
||||
|
||||
def getMetaHash(target):
|
||||
|
@ -57,7 +57,9 @@ def getTimetable(full :bool = False):
|
||||
response = requests.get(downloadUrl, auth=(CORPUS_USER, CORPUS_PASS))
|
||||
mongo.incrementCounter("schedule_api")
|
||||
log.out(f"timetable.getTimetable: Fetch (Full:{full}) response: {response.status_code}", "DBUG")
|
||||
return zlib.decompress(response.content, 16+zlib.MAX_WBITS)
|
||||
decompressed = zlib.decompress(response.content, 16+zlib.MAX_WBITS)
|
||||
#print(decompressed)
|
||||
return decompressed
|
||||
|
||||
def loopTimetable(data):
|
||||
listify = data.splitlines()
|
||||
@ -71,10 +73,10 @@ def loopTimetable(data):
|
||||
# Do something with this data here
|
||||
# Check if timestamp and sequence are correct, if not trigger a full download
|
||||
elif ('TiplocV1' in dic):
|
||||
print("Disregarding TIPLOC Data")
|
||||
pass
|
||||
# Not used as TIPLOCs etc. are sourced from CORPUS
|
||||
elif ('JsonAssociationV1' in dic):
|
||||
print("JsonAssociationData")
|
||||
pass
|
||||
# Associates trains with eachother - not planning to use yet.
|
||||
elif ('JsonScheduleV1' in dic):
|
||||
document = insertSchedule(dic)
|
||||
@ -108,18 +110,22 @@ def insertSchedule(sch_record):
|
||||
else:
|
||||
now = datetime.now()
|
||||
scheduleStart = now.replace(hour=0,minute=0,second=0,microsecond=0)
|
||||
if ('schedule_end_date' in schedule):
|
||||
scheduleEnd = _helpParseDate(schedule['schedule_end_date'], "end")
|
||||
else:
|
||||
scheduleEnd = "null"
|
||||
document = {
|
||||
'transactionType': schedule['transaction_type'],
|
||||
'stpIndicator': schedule['CIF_stp_indicator'],
|
||||
'transactionType': schedule.get('transaction_type'),
|
||||
'stpIndicator': schedule.get('CIF_stp_indicator'),
|
||||
'trainUid': scheduleId,
|
||||
'headcode': schedule['schedule_segment']['signalling_id'],
|
||||
'powerType': schedule['schedule_segment']['CIF_power_type'],
|
||||
'planSpeed': schedule['schedule_segment']['CIF_speed'],
|
||||
'headcode': schedule.get('schedule_segment', {}).get('signalling_id'),
|
||||
'powerType': schedule.get('schedule_segment', {}).get('CIF_power_type'),
|
||||
'planSpeed': schedule.get('schedule_segment', {}).get('CIF_speed'),
|
||||
'scheduleStartDate': scheduleStart,
|
||||
'scheduleEndDate': _helpParseDate(schedule['schedule_end_date'], "end"),
|
||||
'daysRun': _helpParseDays(schedule['schedule_days_runs'])
|
||||
'scheduleEndDate': scheduleEnd,
|
||||
'daysRun': _helpParseDays(schedule.get('schedule_days_runs', '0000000'))
|
||||
}
|
||||
if ('schedule_location' in schedule['schedule_segment']):
|
||||
if ('schedule_location' in schedule.get('schedule_segment', {})):
|
||||
stops = _helpParseStops(schedule['schedule_segment']['schedule_location'])
|
||||
else:
|
||||
stops = []
|
||||
@ -137,7 +143,7 @@ def _insertToDb(data :list, type :str):
|
||||
singleList = [item]
|
||||
mongo.putTimetable(singleList)
|
||||
elif item['transactionType'] == "Delete":
|
||||
mongo.deleteTimetableData({'trainUid': item.trainUid})
|
||||
mongo.deleteTimetableData({'trainUid': item['trainUid']})
|
||||
return True #If Successful else False
|
||||
|
||||
def _helpParseStops(schedule_segment):
|
||||
|
Reference in New Issue
Block a user