From 80cc719d353eb5ec511aeeef309218dea1d768a7 Mon Sep 17 00:00:00 2001 From: Christian Struck Date: Mon, 28 Jan 2013 18:14:23 +0100 Subject: Fixed a bug, where the Vehicle conversion did not work properly --- bvggrabber/api/scheduleddeparture.py | 16 +++++++++------- bvggrabber/utils/__init__.py | 0 bvggrabber/utils/format.py | 7 +++++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 bvggrabber/utils/__init__.py create mode 100644 bvggrabber/utils/format.py (limited to 'bvggrabber') diff --git a/bvggrabber/api/scheduleddeparture.py b/bvggrabber/api/scheduleddeparture.py index 4531caa..4858d18 100644 --- a/bvggrabber/api/scheduleddeparture.py +++ b/bvggrabber/api/scheduleddeparture.py @@ -7,19 +7,21 @@ from bs4 import BeautifulSoup from bvggrabber.api import QueryApi, Departure, hourformat +from bvggrabber.utils.format import int2bin + SCHEDULED_QUERY_API_ENDPOINT = 'http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox' class Vehicle(): - S = 1 - U = 2 - TRAM = 4 + S = 64 + U = 32 + TRAM = 16 BUS = 8 - FERRY = 16 - RB = 32 - IC = 64 + FERRY = 4 + RB = 2 + IC = 1 _ALL = 127 @@ -35,7 +37,7 @@ class ScheduledDepartureQueryApi(QueryApi): else: raise ValueError("Invalid type for station") self.station = station - self.vehicles = bin(vehicles)[2:] + self.vehicles = int2bin(vehicles) self.limit = limit def call(self): diff --git a/bvggrabber/utils/__init__.py b/bvggrabber/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bvggrabber/utils/format.py b/bvggrabber/utils/format.py new file mode 100644 index 0000000..98bbaee --- /dev/null +++ b/bvggrabber/utils/format.py @@ -0,0 +1,7 @@ +#-*- coding: utf-8 -*- + +def int2bin(i, length): + + if not isinstance(length, int): + raise ValueError("expected int for length") + return ('{:0>' + str(length) + 'b}').format(i) -- cgit v1.2.3