diff options
author | Markus Holtermann <info@markusholtermann.eu> | 2014-10-10 01:01:18 +0200 |
---|---|---|
committer | Markus Holtermann <info@markusholtermann.eu> | 2014-10-10 01:01:18 +0200 |
commit | 52c014264138af5d4f8a7b34fdf431abe689943d (patch) | |
tree | 36a690ab60a6c0dfcd8eab8514061c02812796cb | |
parent | e1cb4f1d11c6f9bd7304b608023abc52a33f9026 (diff) | |
download | bvg-grabber-52c014264138af5d4f8a7b34fdf431abe689943d.tar.gz bvg-grabber-52c014264138af5d4f8a7b34fdf431abe689943d.tar.bz2 bvg-grabber-52c014264138af5d4f8a7b34fdf431abe689943d.zip |
Fixed #8 -- Added support for limit to ActualDepartureQueryApi
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | README.rst | 2 | ||||
-rwxr-xr-x | bvg-grabber.py | 12 | ||||
-rw-r--r-- | bvggrabber/api/actualdeparture.py | 9 |
4 files changed, 19 insertions, 10 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 2392787..413e801 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,12 @@ Changes ======= +v0.1.2 (under development) +========================== + +* Added support for limiting queries to ``ActualDepartureQueryApi`` (#8) + + v0.1.1 (2014-10-08) =================== @@ -66,7 +66,7 @@ Usage --vehicle [{S,U,TRAM,BUS,FERRY,RB,IC} [{S,U,TRAM,BUS,FERRY,RB,IC} ...]] Vehicles which shall be queried, if non given actualdepartue (bus) will be used - --limit LIMIT Max departures to query + --limit LIMIT Max departures to query. Default: 9 Example:: diff --git a/bvg-grabber.py b/bvg-grabber.py index 63f37d5..3964f83 100755 --- a/bvg-grabber.py +++ b/bvg-grabber.py @@ -21,7 +21,8 @@ if __name__ == '__main__': choices=vehicle_choices, help='Vehicles which shall be queried, if non given ' 'actualdepartue (bus) will be used') - parser.add_argument('--limit', type=int, help='Max departures to query') + parser.add_argument('--limit', type=int, default=9, + help='Max departures to query. Default: 9') args = parser.parse_args() query = None @@ -44,18 +45,15 @@ if __name__ == '__main__': vehicles |= Vehicle.RB elif vehicle == 'IC': vehicles |= Vehicle.IC - limit = 9 - if args.limit: - limit = args.limit - query = ScheduledDepartureQueryApi(args.station, vehicles, limit=limit) + query = ScheduledDepartureQueryApi(args.station, vehicles, limit=args.limit) res = query.call() if bus: - aquery = ActualDepartureQueryApi(args.station) + aquery = ActualDepartureQueryApi(args.station, limit=args.limit) res2 = aquery.call() res.merge(res2) else: - query = ActualDepartureQueryApi(args.station) + query = ActualDepartureQueryApi(args.station, limit=args.limit) res = query.call() if args.file in ('stdout', '-'): diff --git a/bvggrabber/api/actualdeparture.py b/bvggrabber/api/actualdeparture.py index 54eb6a7..a1b3b5a 100644 --- a/bvggrabber/api/actualdeparture.py +++ b/bvggrabber/api/actualdeparture.py @@ -11,7 +11,7 @@ ACTUAL_API_ENDPOINT = 'http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox?ld=0.1&r class ActualDepartureQueryApi(QueryApi): - def __init__(self, station): + def __init__(self, station, limit=5): super(ActualDepartureQueryApi, self).__init__() if isinstance(station, str): self.station_enc = station.encode('iso-8859-1') @@ -20,9 +20,14 @@ class ActualDepartureQueryApi(QueryApi): else: raise ValueError("Invalid type for station") self.station = station + self.limit = limit def call(self): - params = {'input': self.station_enc, 'start': 'suchen'} + params = { + 'input': self.station_enc, + 'maxJourneys': self.limit, + 'start': 'suchen', + } response = requests.get(ACTUAL_API_ENDPOINT, params=params) if response.ok: soup = BeautifulSoup(response.text) |