def dbapis_importstations_parse_station_row(row, agency_pk, source_pk, kind_pk): hafas_client = HafasClient(DBProfile()) agency = Agency.objects.get(pk=agency_pk) source = Source.objects.get(pk=source_pk) kind = StopIDKind.objects.get(pk=kind_pk) if row['EVA_NR'] == '': return stop = Stop.objects.filter( stopid__name=row['EVA_NR'], stopid__kind__in=agency.used_id_kind.all()).first() if stop is None: stop = Stop() stop.save() StopName.objects.get_or_create(name=row['NAME'], stop=stop, source=source) StopID.objects.get_or_create(stop=stop, name=row['EVA_NR'], source=source, kind=kind) try: StopLocation.objects.get(stop=stop, source=source) except ObjectDoesNotExist: try: hafasLocation = hafas_client.locations(row['EVA_NR'])[0] StopLocation.objects.create(stop=stop, latitude=hafasLocation.latitude, longitude=hafasLocation.longitude, source=source) except IndexError: return
def test_db_locations_request(): client = HafasClient(DBProfile()) locations = client.locations(term="Köln Messe/Deutz") assert len(locations) >= 1
def test_vsn_locations_request(): client = HafasClient(VSNProfile()) locations = client.locations(term="Göttingen Bahnhof/ZOB") assert len(locations) >= 1
print( client.departures(station='8000128', date=datetime.datetime.now(), max_trips=5)) print( client.arrivals(station='8005556', date=datetime.datetime.now(), max_trips=5)) print( client.journey( '¶HKI¶T$A=1@O=Berlin Jungfernheide@L=8011167@a=128@$A=1@O=Berlin Hbf (tief)@L=8098160@a=128@$202002101544$202002101549$RB 18521$$1$§T$A=1@O=Berlin Hbf (tief)@L=8098160@a=128@$A=1@O=München Hbf@L=8000261@a=128@$202002101605$202002102002$ICE 1007$$1$' )) print( client.journeys(destination="8000207", origin="8005556", date=datetime.datetime.now(), min_change_time=0, max_changes=-1)) print(client.locations("Köln Hbf")) print(client.trip("1|1372374|3|80|9062020")) print('=' * 20) vsn = HafasClient(VSNProfile()) print( vsn.departures(station='9034033', date=datetime.datetime.now(), max_journeys=5))
id_kongebakken9 = 'A=2@O=Kongebakken 9, 2765 Smørum, Egedal Kommune@X=12294403@Y=55749256@U=103@L=902400113@B=1@p=1618386996@' #print(client.departures( # station=id_nordhavn, # date=datetime.datetime.now(), # max_trips=5 #)) #print(client.arrivals( # station=id_nordhavn, # date=datetime.datetime.now(), # max_trips=5 #)) # Test searching for an address locs = client.locations("Kongebakken 9, 2765 Smørum", rtype='ALL') assert (locs[0].lid == id_kongebakken9) possibilities = client.journeys(origin=id_nordhavn, destination=id_kongebakken9, date=datetime.datetime.now(), min_change_time=0, max_changes=-1) for p in possibilities: print('--------') for l in p.legs: print(l.departure, l.origin.name, "--> " + str(l.name) + " -->") l = p.legs[-1] print(l.arrival, l.destination.name)