From 589df8813ea7732501fb551296d8fd45c4186217 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Thu, 22 Jun 2023 11:10:59 +0530 Subject: Improve CLI arguments, add basic tag support, add CSS --- serve.py | 81 +++++++++++++++------ .../OpenSans-Italic-VariableFont_wdth,wght.ttf | Bin 0 -> 580356 bytes .../OpenSans/OpenSans-VariableFont_wdth,wght.ttf | Bin 0 -> 529700 bytes static/styles/main.css | 48 ++++++++++++ views/add_feed.tpl | 8 +- views/index.tpl | 55 +++++++++----- 6 files changed, 148 insertions(+), 44 deletions(-) create mode 100644 static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf create mode 100644 static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf create mode 100644 static/styles/main.css diff --git a/serve.py b/serve.py index 7e07fdc..2f45d3e 100755 --- a/serve.py +++ b/serve.py @@ -1,17 +1,19 @@ #!/usr/bin/env python3 -from gevent import monkey +import gevent.monkey -monkey.patch_all() +gevent.monkey.patch_all() import bottle import feedparser import gevent.lock import argparse -import datetime +import os +import pathlib +import time parser = argparse.ArgumentParser() -parser.add_argument("host", nargs="?", default="localhost") -parser.add_argument("-p", "--port", default=8000, type=int) +parser.add_argument("--host", default="localhost") +parser.add_argument("--port", default=8000, type=int) args = parser.parse_args() feeds_lock = gevent.lock.RLock() @@ -20,8 +22,27 @@ feeds = {} feed_items_lock = gevent.lock.RLock() feed_items = [] -def store_feed(feed_url: str): - ... + +def parse_space_separated_tags(inp: str) -> list[str]: + tags = [] + tag = "" + escaped = False + for c in inp: + match c: + case "\\": + if not escaped: + escaped = True + continue + case " ": + if not escaped: + tags.append(tag) + tag = "" + continue + escaped = False + tag += c + if tag: + tags.append(tag) + return tags @bottle.route("/") @@ -29,6 +50,7 @@ def index(): with feed_items_lock: return bottle.template("index", items=feed_items) + @bottle.get("/add_feed") def add_feed_ui(): return bottle.template("add_feed") @@ -37,38 +59,51 @@ def add_feed_ui(): @bottle.post("/add_feed") def add_feed_effect(): feed_source = bottle.request.forms.get("feed_source") + tags = parse_space_separated_tags(bottle.request.forms.get("tags")) + already_present: bool = False with feeds_lock: if feed_source not in feeds: - feeds[feed_source] = {} + feeds[feed_source] = {"tags": tags} else: already_present = True - print(feeds) + feed = feedparser.parse(feed_source) with feed_items_lock: for entry in reversed(feed.entries): try: - date_published = datetime.datetime(*(entry.published_parsed[0:6])).strftime("%x %X") + date_published = time.strftime("%x %X", entry.published_parsed) except AttributeError: date_published = None try: - date_updated = datetime.datetime(*(entry.updated_parsed[0:6])).strftime("%x %X") + date_updated = time.strftime("%x %X", entry.updated_parsed) except AttributeError: date_updated = None if date_updated == date_published: date_updated = None - feed_items.append({ - "title": entry["title"], - "link": entry["link"], - "date_published": date_published, - "date_updated": date_updated, - }) - return bottle.template("add_feed", after_add=True, feed_source=feed_source, already_present=already_present) - - -@bottle.get("/modify_feed") -def modify_feed_ui(): - ... + feed_items.append( + { + "title": entry["title"], + "link": entry["link"], + "date_published": date_published, + "date_updated": date_updated, + "feed": { + "tags": tags, + }, + } + ) + + return bottle.template( + "add_feed", + after_add=True, + feed_source=feed_source, + already_present=already_present, + ) + + +@bottle.get("/static/") +def serve_static(path): + return bottle.static_file(path, pathlib.Path(os.getcwd(), "static")) bottle.run(host=args.host, port=args.port, server="gevent") diff --git a/static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf b/static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000..5bda9cc Binary files /dev/null and b/static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf differ diff --git a/static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf b/static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000..e4142bf Binary files /dev/null and b/static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf differ diff --git a/static/styles/main.css b/static/styles/main.css new file mode 100644 index 0000000..deea098 --- /dev/null +++ b/static/styles/main.css @@ -0,0 +1,48 @@ +@font-face { + font-family: "Open Sans"; + src: url("/static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf") format("truetype-variations"); + font-weight: 100 1000; +} + +@font-face { + font-family: "Open Sans"; + src: url("/static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf") format("truetype-variations"); + font-style: italic; + font-weight: 100 1000; +} + +:root { + font-family: "Open Sans", sans-serif; +} + +table { + width: 100%; + border-collapse: collapse; + border: 1px solid black; +} + +th, td { + border: 1px solid black; +} + +.hover-help { + cursor: help; + user-select: none; + padding-left: 0.2em; +} + +@media (pointer: coarse), (hover: none) { + div.side-by-side-help-container { + display: table-row; + } + + div.side-by-side-help-container > * { + display: table-cell; + } + + div.side-by-side-help-container > .hover-help:focus::after { + content: attr(title); + font-size: small; + padding-left: 0.2em; + } +} diff --git a/views/add_feed.tpl b/views/add_feed.tpl index bac78b0..3c54ffb 100644 --- a/views/add_feed.tpl +++ b/views/add_feed.tpl @@ -3,7 +3,8 @@ - Add Feed + Add Feed | TagRSS + < home @@ -18,6 +19,11 @@

+
+ + 🛈 +
+
diff --git a/views/index.tpl b/views/index.tpl index b08ce0f..d521810 100644 --- a/views/index.tpl +++ b/views/index.tpl @@ -3,31 +3,46 @@ - View Feeds + View Feeds | TagRSS + +

TagRSS

+ - - - - - % for i, item in enumerate(reversed(items)): + - - <% - dates = [] - if item.get("date_published", None): - dates.append(item["date_published"]) - end - if item.get("date_updated", None): - dates.append(item["date_updated"]) - end - %> - + + + + - % end + + + % for i, item in enumerate(reversed(items)): + + + + <% + dates = [] + if item.get("date_published", None): + dates.append(item["date_published"]) + end + if item.get("date_updated", None): + dates.append(item["date_updated"]) + end + %> + + + + % end +
TitleDate
{{item["title"]}} - {{", updated ".join(dates)}} - #TitleDateTags
{{i + 1}}{{item["title"]}} + {{", updated ".join(dates)}} + + {{", ".join(item["feed"]["tags"])}} +
-- cgit v1.2.3-57-g22cb