else:
return (station, 'Wien')
+def guess_location_type(location):
+ """Guess type (stop, address, poi) of a location
+
+ >>> guess_location_type('pilgramgasse')
+ 'stop'
+
+ >>> guess_location_type('karlsplatz 14')
+ 'address'
+
+ >>> guess_location_type('reumannplatz 12/34')
+ 'address'
+ """
+ parts = location.split()
+ first_part = parts[0]
+ last_part = parts[-1]
+
+ # Assume all single-word locations are stops
+ if len(parts) == 1:
+ return 'stop'
+
+ # If the last part is numeric, assume address
+ if last_part.isdigit() and len(parts) > 1:
+ return 'address'
+
+ # Addresses with door number (e.g. "12/34")
+ if all(x.isdigit() or x == '/' for x in last_part):
+ return 'address'
+
+ # Sane default - assume it's a stop/station name
+ return 'stop'
+
def search(origin_tuple, destination_tuple, dtime=None):
""" build route request
returns html result (as urllib response)
if not origin_type in POSITION_TYPES or\
not destination_type in POSITION_TYPES:
+
+ if origin_type is None:
+ origin_type = guess_location_type(origin)
+ print 'Guessed origin type:', origin_type
+
+ if destination_type is None:
+ destination_type = guess_location_type(destination)
+ print 'Guessed destination type:', destination_type
+
+ if (origin_type not in POSITION_TYPES or
+ destination_type not in POSITION_TYPES):
raise ParserError('Invalid position type')
post = defaults.search_post
return PageType.UNKNOWN
+ state = property(check_page)
+
def get_correction(self):
names_origin = self.soup.find('select', {'id': 'nameList_origin'})
names_destination = self.soup.find('select', {'id': 'nameList_destination'})