fixed/workaround "Siebenhirte" bug
[pywienerlinien] / gotovienna / realtime.py
index e8ecb47..3e6dd5c 100644 (file)
@@ -27,7 +27,7 @@ class ITipParser:
             bs = BeautifulSoup(urlopen(self.lines[name]))
             tables = bs.findAll('table', {'class': 'text_10pix'})
             for i in range(2):
-                dir = tables[i].div.contents[-1].strip(' ')
+                dir = tables[i].div.contents[-1].strip()[6:-6]
 
                 sta = []
                 for tr in tables[i].findAll('tr', {'onmouseout': 'obj_unhighlight(this);'}):
@@ -81,7 +81,8 @@ class ITipParser:
             # FIXME prevent from calling this method with None
             return []
 
-        bs = BeautifulSoup(urlopen(url))
+        # open url for 90 min timeslot / get departure for next 90 min
+        bs = BeautifulSoup(urlopen(url + "&departureSizeTimeSlot=90"))
         result_lines = bs.findAll('table')[-1].findAll('tr')
 
         dep = []
@@ -90,10 +91,12 @@ class ITipParser:
             if len(th) < 2:
                 #TODO replace with logger
                 print "[DEBUG] Unable to find th in:\n%s" % str(tr)
-                continue
-
+            elif len(th) == 2:
+                t = th[-1]
+            else:
+                t = th[-2]
             # parse time
-            time = th[-2].text.split(' ')
+            time = t.text.split(' ')
             if len(time) < 2:
                 #print 'Invalid time: %s' % time
                 # TODO: Issue a warning OR convert "HH:MM" format to countdown
@@ -188,26 +191,26 @@ class Line:
             self.name = name.strip()
         else:
             raise LineNotFoundError('There is no line "%s"' % name.strip())
-        
+
     @property
     def stations(self):
         if not self._stations:
             self._stations = parser.get_stations(self.name)
         return self._stations
-    
+
     def get_departures(self, stationname):
         stationname = stationname.strip().lower()
         stations = self.stations
-        
+
         found = false
-        
+
         for direction in stations.keys():
             # filter stations starting with stationname
             stations[direction] = filter(lambda station: station[0].lower().starts_with(stationname), stations)
             found = found or bool(stations[direction])
-        
+
         if found:
             # TODO return departures
             raise NotImplementedError()
         else:
-            raise StationNotFoundError('There is no stationname called "%s" at route of line "%s"' % (stationname, self.name))
\ No newline at end of file
+            raise StationNotFoundError('There is no stationname called "%s" at route of line "%s"' % (stationname, self.name))