diff --git a/src/timetable.py b/src/timetable.py index 5840e5b..9d57274 100644 --- a/src/timetable.py +++ b/src/timetable.py @@ -141,18 +141,23 @@ def insertSchedule(sch_record): return document def _insertToDb(data :list, type :str): - if type == "full": - mongo.dropCollection("timetable") - mongo.putTimetable(data) - mongo.createSingleIndex("timetable", "headcode") - elif type == "update": - for item in data: - if item['transactionType'] == "Create": - singleList = [item] - mongo.putTimetable(singleList) - elif item['transactionType'] == "Delete": - mongo.deleteTimetableData({'trainUid': item['trainUid']}) - return True #If Successful else False + try: + if type == "full": + mongo.dropCollection("timetable") + mongo.putTimetable(data) + mongo.createSingleIndex("timetable", "headcode") + elif type == "update": + for item in data: + if item['transactionType'] == "Create": + singleList = [item] + mongo.putTimetable(singleList) + elif item['transactionType'] == "Delete": + mongo.deleteTimetableData({'trainUid': item['trainUid']}) ## 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. + return True #If Successfuls + except Exception as e: + log.out("timetable._insertToDb: Error inserting timetable data", "ERR") + log.out(f"timteable._insertToDb: {e}") + return False # If error inserting timetable def _helpParseStops(schedule_segment): stops = []