Ejemplo n.º 1
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data = parse_response(res)

        instances = []
        for d in data:
            try:
                date = dp.parse(d['dc:date'])
                conn_railways = ','.join(d['odpt:connectingRailway'])
                exits = ','.join(d['odpt:exit']) if d['odpt:exit'] else ''
                surveys = ','.join(d['odpt:passengerSurvey'])

                instances.append(
                    cls(ld_context=d['@context'],
                        ld_id=d['@id'],
                        ld_type=d['@type'],
                        same_as=d['owl:sameAs'],
                        date=date,
                        title=d['dc:title'],
                        connecting_railways=conn_railways,
                        exits=exits,
                        facility=d['odpt:facility'],
                        operator=d['odpt:operator'],
                        passenger_surveys=surveys,
                        railway_id=d['odpt:railway'],
                        station_code=d['odpt:stationCode'],
                        region=d['ug:region']))
            except:
                print d
                raise
        for ins in instances:
            ins.save()
Ejemplo n.º 2
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data = parse_response(res)

        for d in data:
            try:
                date = dp.parse(d['dc:date'])

                rw = cls(ld_context=d['@context'],
                         ld_id=d['@id'],
                         ld_type=d['@type'],
                         same_as=d['owl:sameAs'],
                         date=date,
                         title=d['dc:title'],
                         operator=d['odpt:operator'],
                         line_code=d['odpt:lineCode'],
                         region=d['ug:region'])
                rw.save()

                # save StationOrder
                so_list = d['odpt:stationOrder']
                for so in so_list:
                    st = Station.get_or_create(so['odpt:station'])
                    StationOrder.get_or_create(rw, st, so['odpt:index'])
                # save TravelTime
                tt_list = d['odpt:travelTime']
                for tt in tt_list:
                    fs = Station.get_or_create(tt['odpt:fromStation'])
                    ts = Station.get_or_create(tt['odpt:toStation'])
                    TravelTime.get_or_create(rw, fs, ts,
                                             tt['odpt:necessaryTime'],
                                             tt['odpt:trainType'])
                # save WomenOnlyCar
                if 'odpt:womenOnlyCar' in d:
                    woc_list = d['odpt:womenOnlyCar']
                    for woc in woc_list:
                        fs = Station.get_or_create(woc['odpt:fromStation'])
                        ts = Station.get_or_create(woc['odpt:toStation'])
                        time_from = dp.parse(
                            woc['odpt:availableTimeFrom']).time()
                        time_until = dp.parse(
                            woc['odpt:availableTimeUntil']).time()
                        WomenOnlyCar.get_or_create(rw, fs, ts,
                                                   woc['odpt:operationDay'],
                                                   time_from, time_until,
                                                   woc['odpt:carComposition'],
                                                   woc['odpt:carNumber'])
            except:
                print d
                raise
Ejemplo n.º 3
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data  = parse_response(res)
        
        for d in data:
            try:
                date = dp.parse(d['dc:date'])

                rw = cls(ld_context   = d['@context'],
                    ld_id        = d['@id'],
                    ld_type      = d['@type'],
                    same_as      = d['owl:sameAs'],
                    date         = date,
                    title        = d['dc:title'],
                    operator     = d['odpt:operator'],
                    line_code = d['odpt:lineCode'],
                    region       = d['ug:region']
                    )
                rw.save()

                # save StationOrder
                so_list = d['odpt:stationOrder']
                for so in so_list:
                    st = Station.get_or_create(so['odpt:station'])
                    StationOrder.get_or_create(rw, st, so['odpt:index'])
                # save TravelTime 
                tt_list = d['odpt:travelTime']
                for tt in tt_list:
                    fs = Station.get_or_create(tt['odpt:fromStation'])
                    ts = Station.get_or_create(tt['odpt:toStation'])
                    TravelTime.get_or_create(rw, fs, ts, tt['odpt:necessaryTime'], tt['odpt:trainType'])
                # save WomenOnlyCar 
                if 'odpt:womenOnlyCar' in d:
                    woc_list = d['odpt:womenOnlyCar']
                    for woc in woc_list:
                        fs = Station.get_or_create(woc['odpt:fromStation'])
                        ts = Station.get_or_create(woc['odpt:toStation'])
                        time_from = dp.parse(woc['odpt:availableTimeFrom']).time()
                        time_until = dp.parse(woc['odpt:availableTimeUntil']).time()
                        WomenOnlyCar.get_or_create(rw, fs, ts, woc['odpt:operationDay'], time_from, time_until,
                                woc['odpt:carComposition'], woc['odpt:carNumber'])
            except:
                print d
                raise
Ejemplo n.º 4
0
    def import_all(cls):
        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data  = parse_response(res)
        
        instances = []
        for d in data:
            try:
                date = dp.parse(d['dc:date'])
                valid = dp.parse(d['dct:valid'])
                from_station = Station.get_or_create(d['odpt:fromStation'])
                starting_station = Station.get_or_create(d['odpt:startingStation'])
                terminal_station = Station.get_or_create(d['odpt:terminalStation'])
                to_station = Station.get_or_create(d['odpt:toStation'])

                cls(ld_context       = d['@context'],
                    ld_id            = d['@id'],
                    ld_type          = d['@type'],
                    date             = date,
                    valid            = valid,
                    delay            = d['odpt:delay'],
                    frequency        = d['odpt:frequency'],
                    from_station     = from_station,
                    rail_direction   = d['odpt:railDirection'],
                    railway          = d['odpt:railway'],
                    starting_station = starting_station,
                    terminal_station = terminal_station,
                    to_station       = to_station,
                    train_number     = d['odpt:trainNumber'],
                    train_owner      = d['odpt:trainOwner'],
                    train_type       = d['odpt:trainType'],
                    same_as          = d['owl:sameAs'],
                    from_station_raw  = d['odpt:fromStation'],
                    starting_station_raw  = d['odpt:startingStation'],
                    terminal_station_raw  = d['odpt:terminalStation'],
                    to_station_raw  = d['odpt:toStation'],
                    ).save()
            except:
                print sys.exc_info() 
                print d
Ejemplo n.º 5
0
    def import_all(cls):
        cls.objects.all().delete()

        prm = create_prm(cls.RDF_TYPE)
        res = request_metro(prm)
        data = parse_response(res)

        instances = []
        for d in data:
            try:
                date = dp.parse(d["dc:date"])
                conn_railways = ",".join(d["odpt:connectingRailway"])
                exits = ",".join(d["odpt:exit"]) if d["odpt:exit"] else ""
                surveys = ",".join(d["odpt:passengerSurvey"])

                instances.append(
                    cls(
                        ld_context=d["@context"],
                        ld_id=d["@id"],
                        ld_type=d["@type"],
                        same_as=d["owl:sameAs"],
                        date=date,
                        title=d["dc:title"],
                        connecting_railways=conn_railways,
                        exits=exits,
                        facility=d["odpt:facility"],
                        operator=d["odpt:operator"],
                        passenger_surveys=surveys,
                        railway_id=d["odpt:railway"],
                        station_code=d["odpt:stationCode"],
                        region=d["ug:region"],
                    )
                )
            except:
                print d
                raise
        for ins in instances:
            ins.save()