open_bus_api package
Submodules
open_bus_api.api module
open_bus_api.config module
- class open_bus_api.config.APIKey(api_env, api_file)
Bases:
objectClass to manage access to the Open Bus data API key. First it searches for a key in the system environment. Second it searches for a key in an api_file. If no key is found, an error occurs.
- get_key()
Returns a string containing the API key.
- print_message()
Print the message to the console explaining the API key.
- class open_bus_api.config.Config(config_file: str | Path | None = None, schema_file: str = 'config.schema.json', schema_dir: str = 'static', **kwargs)
Bases:
objectOpen Bus API configuration
- open_bus_api.config.json_load(file: str) dict
Read JSON file to dictionary
- Args:
file (str): JSON file path
Returns: JSON dictionary
- open_bus_api.config.load_json(file)
Load JSON file to dictionary or return empty dictionary if file does not exist.
- Args:
file (str): JSON file path
Returns: JSON dictionary
- open_bus_api.config.print_header()
- open_bus_api.config.validate_config(input_data: dict, schema: dict)
Validate the configuration data against the schema. Fill the data with default values for missing fields.
- Args:
input_data (dict): Input configuration data schema (dict): Configuration data schema
open_bus_api.functions module
- open_bus_api.functions.database_setup(config: Config)
Wrapper for setup_database
- Args:
config (Config): configuration object
- open_bus_api.functions.fetch_stops_code_data(path, codes: str) str
Fetches the stops data on vehicles in the provided area from the database
- Args:
path (str): Path to the database codes (str): List of comma separated codes in string format
Returns: Stops data in JSON format
- open_bus_api.functions.fetch_stops_data(path, min_lat: float, min_long: float, max_lat: float, max_long: float) str
Fetches the stops data on vehicles in the provided area from the database
- Args:
path (str): Path to the database min_lat (float): Minimum latitude min_long (float): Minimum longitude max_lat (float): Maximum latitude max_long (float): Maximum longitude
Returns: Result of database query in JSON format
- open_bus_api.functions.get_version() str
Gets the version of Open-Bus API from its metadata.
Returns: Version string
- open_bus_api.functions.index_page() str
Renders the index page
Returns: The index page
- open_bus_api.functions.location_data(min_lat: float, min_long: float, max_lat: float, max_long: float, **kwargs) bytes
Fetches the locations data on vehicles in the provided area from the API
- Args:
min_lat (float): Minimum latitude min_long (float): Minimum longitude max_lat (float): Maximum latitude max_long (float): Maximum longitude
Returns: API response data in XML format
- open_bus_api.functions.markdown_to_html(input: str) str
- open_bus_api.functions.operators_data(path: str) str
Fetches the operators database
path (str): Path to the database
Returns: The operators data in JSON format
- open_bus_api.functions.operators_info_list(path: str) str
Returns a summary of the contents of the operators database
path (str): Path to the database
Returns: Page describing the contents of the operators database
- open_bus_api.functions.setup_operators_info_page(conn: Connection) Markup
Renders a list of the operators data as HTML Markup
conn (Connection): Database connection
Returns: The operators data list as HTML
- open_bus_api.functions.vehicle_location_data(vehicle_id: str, **kwargs) bytes
Fetches the locations data on vehicle with id vehicle_id from the API
- Args:
vehicle_id (str): Vehicle ID for the API request
Returns: API response data in XML format