from typing import Any import bottle # type: ignore from tinydb import Query from app.DatabaseManager import database_manager def feed_id_to_li(feed_id: str) -> str: return f'
  • {feed_id}
  • ' def feed_ids_to_ul(feed_ids: list[str]) -> str: if len(feed_ids) == 0: return "No feeds (yet). Add feeds by defining them in your Aggrofile. If you did that already, you might have to wait a bit for the data to propagate." lis = [feed_id_to_li(feed_id) for feed_id in feed_ids] return "" @bottle.route("/") def index(): if database_manager.db is None: raise Exception("Database is not initialized") Q = Query() res = database_manager.feeds.all() feeds_ids = [feed["feed_id"] for feed in res] bottle.response.set_header("content-type", "text/html") page = f""" Aggro – Feed manipulator

    Aggro

    Feed manipulator

    List of feeds served at this address

    {feed_ids_to_ul(feeds_ids)} """ return page @bottle.route("/") def feed(feed_id: str): if database_manager.db is None: raise Exception("Database is not initialized") Q = Query() res = database_manager.feeds.search(Q.feed_id == feed_id) if len(res) == 0: bottle.abort(400, f"No feed found with id {feed_id}") if len(res) > 1: bottle.abort(400, f"Weird number of feeds found with id {feed_id}: {len(res)}") bottle.response.set_header("content-type", "application/xml") feed: Any = res[0] # type: ignore feed_xml: str = feed["feed_xml"] return feed_xml def run_web_server(host: str, port: int): bottle.run(host=host, port=port)