aboutsummaryrefslogtreecommitdiffstats
path: root/app/server.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-09-10 11:58:19 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2023-09-10 19:01:00 +0300
commitcfac80ebc88b2256317b98a243083637aa6a5b3c (patch)
tree1f9eddb610ee96d83a49923af89d5611af027d01 /app/server.py
parente54a45b44670aafbd9ad0fdfa70fd1df1857b81b (diff)
Add main html page
Diffstat (limited to 'app/server.py')
-rw-r--r--app/server.py58
1 files changed, 55 insertions, 3 deletions
diff --git a/app/server.py b/app/server.py
index 5de3018..5818179 100644
--- a/app/server.py
+++ b/app/server.py
@@ -1,14 +1,66 @@
from typing import Any
-import bottle as _bottle # type: ignore
+import bottle # type: ignore
from tinydb import Query
from app.DatabaseManager import database_manager
-bottle: Any = _bottle
+
+def feed_id_to_li(feed_id: str) -> str:
+ return f'<li><a href="/{feed_id}">{feed_id}</a></li>'
+
+
+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 "<ul>" + "".join(lis) + "</ul>"
+
+
+@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"""
+ <html lang="en">
+ <head>
+ <title>Aggro &ndash; Feed manipulator</title>
+ <style>
+ body {{
+ font-family: Open Sans, Arial;
+ color: #050505;
+ font-size: 16px;
+ margin: 2em auto;
+ max-width: 800px;
+ padding: 1em;
+ line-height: 1.4;
+ text-align: justify;
+ }}
+ h1 {{
+ margin-bottom: 0;
+ }}
+ </style>
+ </head>
+ <body>
+ <h1>Aggro</h2>
+ <i>Feed manipulator</i>
+ <h2>List of feeds served at this address</h2>
+ {feed_ids_to_ul(feeds_ids)}
+ </body>
+ </html>
+ """
+
+ return page
@bottle.route("/<feed_id>")
-def index(feed_id: str):
+def feed(feed_id: str):
if database_manager.db is None:
raise Exception("Database is not initialized")