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()
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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)
Пример #5
0
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))
#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)
    print("Journey duration: ", p.duration)