def cmdline(): parser = VeliberatorOptionParser( usage=_('%prog [station_id] [address] [options]'), version='%s %s' % ('%prog', veliberator.__version__)) parser.add_option('-d', '--database', dest='database', help=_('The SQLURI of the database'), default=DATABASE_URI) parser.add_option('-p', '--places', dest='places', type='int', help=_('The number of places you want'), default=1) parser.add_option('-m', '--max-stations', dest='max_stations', type='int', help=_('The maximun stations around proposed'), default=5) parser.add_option('--synchronize', dest='synchronize', action='store_true', help=_('Only do a synchronization of the cartography')) (options, args) = parser.parse_args() print '-==* Veliberator v%s *==-' % veliberator.__version__ try: db_connection(options.database) except sqlalchemy.exc.OperationalError: if options.synchronize: sys.exit(_('-> The database %s is unreachable.') % options.database) else: print _('-> The database is unreachable, switch on RAM.') print _('-> Edit the configuration file, ' 'for removing this message.') db_connection('sqlite://') if options.synchronize: synchronization() sys.exit(0) if not StationInformation.query.count(): synchronization() if args: user_input = args[0] else: user_input = raw_input(_('Station ID or complete address:\n')) if user_input.isdigit(): try: station = Station(user_input) except UnknowStation: sys.exit(_('The Station ID does not exist.')) show_status(station) if not station.is_free(options.places): print _('Searching on the closest stations...') display_free_stations(station.stations_around, options.places, options.max_stations) else: try: finder = AddressGeoFinder(user_input) except GeoFinderError: sys.exit(_('The provided address is not valid or imprecise.')) display_free_stations( finder.get_stations_around(STATION_AROUND_RADIUS), options.places, options.max_stations)
def test_GetStationsAround(self): Cartography.synchronize(TEST_XML_URL_DATA_STATION) station = Station(self.velib_id) station.around_radius = 1200 stations_around = station.stations_around self.assertEquals(len(stations_around), 9) Cartography.flush()
def display_free_stations(stations, places, max_display): displayed = 0 for station_information in stations: if displayed == max_display: break station = Station(station_information.id) if station.is_free(places): print '----------' show_status(station, station_information.distance) displayed += 1
def test_repr(self): station = Station(self.velib_id) self.assertEquals(repr(station), '<Station "42008" (Test)>') station.informations = None self.assertEquals(repr(station), '<Station "42008">')
def test_IsAvailable(self): station = Station(self.velib_id) station.status.status["available"] = 5 self.assertTrue(station.is_available()) self.assertTrue(station.is_available(4)) self.assertFalse(station.is_available(7))
def test_IsFree(self): station = Station(self.velib_id) station.status.status["free"] = 5 self.assertTrue(station.is_free()) self.assertTrue(station.is_free(4)) self.assertFalse(station.is_free(7))