diff --git a/data/pis/gwr.yaml b/data/pis/gwr.yaml index 5c811f7..ef87fd2 100644 --- a/data/pis/gwr.yaml +++ b/data/pis/gwr.yaml @@ -2229,6 +2229,14 @@ pis: stops: [bnp,umb,egg,lap,mrd,cop,yeo,cdi,ntc,exd,exc] - code: 6143 stops: [pnz,ser,hyl,cbn,red,tru,sau,par,los,lsk,men,sgm,sts,ply,ivy,tot,nta,tgm,dwl,exd,tvp,tau,bwt,hig,wsm,wnm,wor,yat,nls,psn,bmt,bri,fit,pwy,stj,nwp,cdf] + - code: 8001 + stops: [pnz,ser,cbn,red,tru,sau,bod,lsk,ply,tot,nta,exd,rdg,pad] + - code: 8002 + stops: [pnz,ser,cbn,red,tru,sau,par,bod,lsk,ply,tot,nta,exd,tau,rdg,pad] + - code: 8003 + stops: [pad,rdg,exd,nta,ply,lsk,bod,los,par,sau,tru,red,cbn,hyl,ser,pnz] + - code: 8004 + stops: [pad,rdg,tau,exd,nta,ply,lsk,bod,los,par,sau,tru,red,cbn,hyl,ser,pnz] - code: 9801 stops: [pad,hxx,hwv] - code: 9802 diff --git a/src/mongo.py b/src/mongo.py index fb64350..92be868 100644 --- a/src/mongo.py +++ b/src/mongo.py @@ -186,4 +186,9 @@ def putMetaHash(target :str, hash :str): def query(collection, query): col = db[collection] incrementCounter(collection) - return col.find_one(query) \ No newline at end of file + return col.find_one(query) + +def deleteMany(collection :str, filter :dict): + col = db[collection] + incrementCounter(collection) + return col.delete_many(filter) \ No newline at end of file diff --git a/src/timetable.py b/src/timetable.py index 4fcfaf2..dbbdb9d 100644 --- a/src/timetable.py +++ b/src/timetable.py @@ -96,7 +96,7 @@ def runUpdate(): status = _insertToDb(parsed, required) if (status): mongo.metaUpdateTime("timetable") - log.out("timetable.runUpdate: Removing all out of date schedules", "INFO") + _removeOutdatedServices() ## Check what happens if there is no update def insertSchedule(sch_record): @@ -181,6 +181,12 @@ def _helpParseDate(string :str, time :str = "false"): return datetime.strptime(string, "%Y-%m-%d %H%M%S") def _removeOutdatedServices(): - log.out("timetable._removeOutdatedServices: NOT IMPLEMENTED", "WARN") - # Call 'delete' on all services with an end-date $lte today. - return \ No newline at end of file + log.out("timetable._removeOutdatedServices: Removing out of date schedules", "INFO") + preCount = mongo.getLength("timetable") + query = { + "schedule_end_date": { + "$lte": datetime.now() + } + } + postCount = mongo.getLength("timetable") + log.out(f"timetable._removeOutdatedServices: Removed {preCount - postCount} out of date services", "DBUG") \ No newline at end of file