def get_schedule_message_from_file(self, file_path):
     with open(file_path) as f:
         x = f.read()
         r = pp.CreateFromDocument(x)
         assert(None is r.sR)
         assert(None is not r.uR)
         assert(1 == len(r.uR.schedule))
         
         s = ScheduleXMLMessageFactory.build(r.uR.schedule[0], r, x)
         return s
Beispiel #2
0
    def add_schedule_from_buffer(self, journey_buffer):
        r = pp.CreateFromDocument(journey_buffer)
        assert(None is r.sR)
        assert(None is not r.uR)
        assert(1 == len(r.uR.schedule))

        m = ScheduleXMLMessageFactory.build(r.uR.schedule[0], r, journey_buffer)

        ###### This code below checks that there are no schedules already stored
        # # We try to find a schedule, and replace it if we do
        # found = (Schedule
        #         .select()
        #         .where(
        #             Schedule.uid == m.uid,
        #             Schedule.rid == m.rid
        #         ))

        # count = found.count()
        # if count > 0:
        #     assert(count == 1)
        #     s = found[0]

        #     # Removing all relevant calling points
        #     CallingPoint.delete().where(
        #         CallingPoint.schedule == s
        #     ).execute()

        # else:
        #     s = Schedule()
        #     s.uid = m.uid
        #     s.rid = m.rid


        # Script assumes new schedules added, and overrides any existing
        s = Schedule()
        s.uid = m.uid
        s.rid = m.rid


        s.headcode = m.headcode
        s.start_date = m.start_date
        s.toc_code = m.toc_code
        s.category = m.category
        s.status = m.status
        s.active = m.active
        s.deleted = m.deleted
        s.cancel_tiploc = m.cancel_reason_tiploc
        s.cancel_code = m.cancel_reason_code
        s.cancel_near = m.cancel_reason_near
        s.save()

        for o in m.all_points:
            p = CallingPoint()
            p.tiploc = o.tiploc
            p.schedule = s
            p.activity_codes = o.planned_activity_codes
            p.cancelled = o.cancelled
            p.false_tiploc = o.false_tiploc
            p.route_delay = o.route_delay
            p.working_arrival = o.raw_working_arrival_time
            p.working_pass = o.raw_working_pass_time
            p.working_departure = o.raw_working_departure_time
            p.public_arrival = o.raw_public_arrival_time
            p.public_departure = o.raw_public_departure_time
            p.type = str(type(o))
            p.save()