def test_vsn_journey_request(): client = HafasClient(VSNProfile()) journey = client.journey( journey= "¶HKI¶T$A=1@O=Lenglern Bahnhof@L=9909403@a=128@$A=1@O=Göttingen Bahnhof/ZOB@L=1101000@a=128@$202106051527$202106051550$Bus 220 $$1$$$$", ) assert isinstance(journey, Journey)
def test_db_journey_request(): client = HafasClient(DBProfile()) journey = client.journey( journey= "¶HKI¶T$A=1@O=Siegburg/Bonn@L=8005556@a=128@$A=1@O=Hennef(Sieg)@L=8002753@a=128@$202106051440$202106051445$S 12$$1$$$", ) assert isinstance(journey, Journey)
def handle(self, *args, **options): client = HafasClient(DBProfile()) for start in STOPS: for end in STOPS: if start == end: continue journeys = client.journeys(start, end, date=datetime.datetime.now()) stops = [ Stop.objects.get(stopid__external_id=start), Stop.objects.get(stopid__external_id=end) ] cons = Connection.objects.filter(stop=stops[0]).filter( stop=stops[1]) if len(cons): con = cons[0] else: con = Connection() con.save() con.stop.add(*stops) con.duration = datetime.timedelta(seconds=statistics.mean( [j.duration.total_seconds() for j in journeys])) con.save()
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_journey_request(): client = HafasClient(DBProfile()) journey = client.journey( journey= "¶HKI¶T$A=1@O=Siegburg/Bonn@L=8005556@a=128@$A=1@O=Troisdorf@L=8000135@a=128@$202008081507$202008081512$S 19$$1$$$c", ) assert isinstance(journey, Journey)
def test_vsn_journey_request(): client = HafasClient(VSNProfile()) journey = client.journey( journey= "¶HKI¶T$A=1@O=Göttingen@L=8000128@a=128@$A=1@O=Lenglern@L=8003644@a=128@$202008090710$202008090719$ RB85$$1$$$", ) assert isinstance(journey, Journey)
def test_vsn_journeys_request(): client = HafasClient(VSNProfile()) journeys = client.journeys(destination="009033817", origin="009054997", date=datetime.datetime.now(), min_change_time=0, max_changes=-1) assert journeys
def test_db_journeys_request(): client = HafasClient(DBProfile()) journeys = client.journeys(destination="8000135", origin="8005556", date=datetime.datetime.now(), min_change_time=0, max_changes=-1) assert journeys
def __init__(self): self.hafasclient = HafasClient(DBProfile()) self.provider = Provider.objects.get(internal_name="db") self.source, _ = Source.objects.get_or_create( internal_name="db_hafas", friendly_name="Deutsche Bahn HAFAS", provider=self.provider) self.idkind, _ = StopIDKind.objects.get_or_create( name='eva', provider=self.provider)
import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import datetime from helpers import StationPhillip from pyhafas import HafasClient from pyhafas.profile import DBProfile stations = StationPhillip() hafas = HafasClient(DBProfile()) # location = hafas.locations() journeys = hafas.journeys( origin=stations.get_eva(name='Tübingen Hbf'), destination=stations.get_eva(name='Köln Hbf'), date=datetime.datetime.now(), ) print(journeys)
def test_vsn_arrivals_request(): client = HafasClient(VSNProfile()) arrivals = client.arrivals(station="009033817", date=datetime.datetime.now(), max_trips=5) assert arrivals
def __init__(self): self.hafasclient = HafasClient(DBProfile()) self.db, _ = Agency.objects.get_or_create(name="db") self.dbapis, _ = Source.objects.get_or_create(name="dbapis") self.idkind, _ = StopIDKind.objects.get_or_create(name='eva') self.timezone = pytz.timezone("Europe/Berlin")
def test_db_arrivals_request(): client = HafasClient(DBProfile()) arrivals = client.arrivals(station="8011160", date=datetime.datetime.now(), max_trips=2) assert len(arrivals) <= 2
def test_vsn_locations_request(): client = HafasClient(VSNProfile()) locations = client.locations(term="Göttingen Bahnhof/ZOB") assert len(locations) >= 1
def test_vsn_departures_request(): client = HafasClient(VSNProfile()) departures = client.departures(station="009033817", date=datetime.datetime.now(), max_trips=5) assert departures
def test_db_departures_request(): client = HafasClient(DBProfile()) departures = client.departures(station="8011160", date=datetime.datetime.now(), max_trips=2) assert len(departures) <= 2
import datetime from pyhafas import HafasClient from pyhafas.profile import DBProfile, VSNProfile client = HafasClient(DBProfile(), debug=True) 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)
def test_db_locations_request(): client = HafasClient(DBProfile()) locations = client.locations(term="Köln Messe/Deutz") assert len(locations) >= 1
import datetime from pyhafas import HafasClient from pyhafas.profile import RKRPProfile client = HafasClient(RKRPProfile(), debug=True) id_nordhavn = '8600653' 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)