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