PK!Uvagquery/__init__.pyfrom .station import Station from .station import StationQuery from .departure import Departure from .departure import DepartureQuery __all__ = ["Station", "StationQuery", "Departure", "DepartureQuery"] PK!)g7vagquery/departure.pyfrom __future__ import unicode_literals import datetime import requests import sys import pytz class Departure(object): def __init__(self, direction, direction_type, stopping_point, type_number, departure_actual, departure_planned, product, trip_id, longitude, latitude, prognosis): self.direction = direction self.direction_type = direction_type self.stopping_point = stopping_point self.type_number = type_number self.departure_actual = departure_actual self.departure_planned = departure_planned self.product = product self.trip_id = trip_id self.longitude = longitude self.latitude = latitude self.prognosis = prognosis @property def departure_in_min(self): departure = self.departure_actual - datetime.datetime.now() return int(departure.total_seconds() / 60) @property def departure_in_min_planned(self): departure = self.departure_planned - datetime.datetime.now() return int(departure.total_seconds() / 60) def __str__(self): if sys.version_info.major >= 3: return self.__unicode__() # pragma: no cover else: return unicode(self).encode('utf-8') # NOQA def __unicode__(self): return '{departure:3} {product:5} -> {direction:20} (ID:{trip_id:5})'.\ format(departure=self.departure_in_min, product=self.product, direction=self.direction, trip_id=self.trip_id) class DepartureQuery(object): def __init__(self, station_id, timedelay=0, bus=True, subway=True, tram=True): products_string = self._build_products_string(bus, subway, tram) self._url = "http://start.vag.de/dm/api/abfahrten.json/vgn/" +\ str(station_id) + "/?timedelay=" +\ str(timedelay) + "&product=" + products_string tz = pytz.timezone('Europe/Berlin').localize( datetime.datetime.now()).strftime('%z') self.tz = tz[:3] + ':' + tz[3:] def query(self): departures = [] r = requests.get(self._url) data_departures = r.json()["Abfahrten"] for departure in data_departures: direction = departure["Richtungstext"] direction_type = departure["Richtung"] stopping_point = departure["Haltepunkt"] type_number = departure["Fahrtartnummer"] _departure_actual = departure["AbfahrtszeitIst"] departure_actual = datetime.datetime.strptime( _departure_actual, "%Y-%m-%dT%H:%M:%S" + self.tz) _departure_planned = departure["AbfahrtszeitSoll"] departure_planned = datetime.datetime.strptime( _departure_planned, "%Y-%m-%dT%H:%M:%S" + self.tz) product = departure["Produkt"] trip_id = departure["Fahrtnummer"] longitude = departure["Longitude"] latitude = departure["Latitude"] prognosis = departure["Prognose"] departures.append( Departure( direction, direction_type, stopping_point, type_number, departure_actual, departure_planned, product, trip_id, longitude, latitude, prognosis )) return departures @staticmethod def _build_products_string(bus, subway, tram): text = list() if not bus and not subway and not tram: raise Exception("No transportation set") if subway: text.append("Ubahn") if bus: text.append("Bus") if tram: text.append("Tram") return ','.join(text) PK!rvagquery/station.pyfrom __future__ import unicode_literals import requests import sys if sys.version_info.major >= 3: # pragma: no cover from urllib.parse import urlencode else: # pragam: no cover from urllib import urlencode class StationQuery(object): def __init__(self, text): _parameter = {'name': text} self._url = 'http://start.vag.de/dm/api/haltestellen.json/vgn?' + \ urlencode(_parameter) def query(self): stations = [] r = requests.get(self._url) stations_data = r.json()["Haltestellen"] for station_data in stations_data: stations.append(Station(station_data["VGNKennung"], station_data["Haltestellenname"], station_data["VAGKennung"])) return stations class Station(object): def __init__(self, station_id, name, vag_name): self.station_id = station_id self.name = name self.vag_name = vag_name def __str__(self): if sys.version_info.major >= 3: # pragma: no cover return self.__unicode__() else: return unicode(self).encode('utf-8') # NOQA def __unicode__(self): return '{station_id:5} {vag_name:10} {station_name}'.\ format(station_id=self.station_id, vag_name=self.vag_name, station_name=self.name) PK!HWYvagquery-1.1.dist-info/WHEEL A н#Z;/"b&F]xzwC;dhfCSTֻ0*Ri.4œh6-]{H, JPK!Hm4| vagquery-1.1.dist-info/METADATAVr6}WlHIN\kOLֵCBB4.RǺ)ZLRxݳ+C'2=+JO/"hj&$N7Ip ?}2g6N8'K1Z.qXϝl2eh,dU2EeIk3Km2 .";nMBV2R"6pڠ3dWxA;ɀ?W|̈́ﳳBX+$R"$ :} Uep&+#Ks#R.=$7a`W}~ū]-wjgKjzTk>>>o:u6r}=8eަIF1>'A0~ H +mӦWMB ϴr𺮈?uL/c'aή9<")uVQ-Sɵɷv7I'M>gDtj=\ Id4YR䱣mN6Lc$Q#$T SOkq0[X'[p=P<',I+fQ8H?Q@SkNR LL;ˈ Kǐ3&> T"K i%! <P0v{{ˀ,;Zq7y$0\*2bΗ"w:'>m^T(՚wzq$°*#5dXQb<(軘) =%p87׌0nA 2`~pcٴTB~/\HoP82h):@ЁT(* Q \2^C )ʝ5_~5f8 `6D_r) [J>7oo M蟠!֊8 a KأD?&IiH Eu1ޯ,} nJ>=DCv?qu(">6^骊޳$Lwl7I*Tawߩ׸a7Q$Uz\Y͸PӢ]}#S#==V[bB-7p.EClSJ|U( }5ПX pڞ;y἞vn} k=->Z,PK!Uvagquery/__init__.pyPK!)g7vagquery/departure.pyPK!rvagquery/station.pyPK!HWYvvagquery-1.1.dist-info/WHEELPK!Hm4| vagquery-1.1.dist-info/METADATAPK!H}nv(vagquery-1.1.dist-info/RECORDPK