aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-06-22 05:40:59 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-06-22 05:40:59 +0000
commit589df8813ea7732501fb551296d8fd45c4186217 (patch)
tree670d915991325c3f1c270be35ad82ba69d1e5cce
parent69a356d177ad98941502b621754d011383e160d9 (diff)
downloadtagrss-589df8813ea7732501fb551296d8fd45c4186217.tar
tagrss-589df8813ea7732501fb551296d8fd45c4186217.tar.gz
tagrss-589df8813ea7732501fb551296d8fd45c4186217.zip
Improve CLI arguments, add basic tag support, add CSS
-rwxr-xr-xserve.py81
-rw-r--r--static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttfbin0 -> 580356 bytes
-rw-r--r--static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttfbin0 -> 529700 bytes
-rw-r--r--static/styles/main.css48
-rw-r--r--views/add_feed.tpl8
-rw-r--r--views/index.tpl55
6 files changed, 148 insertions, 44 deletions
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/<path:path>")
+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
--- /dev/null
+++ b/static/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf
Binary files 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
--- /dev/null
+++ b/static/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf
Binary files 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 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Add Feed</title>
+ <title>Add Feed | TagRSS</title>
+ <link href="/static/styles/main.css" rel="stylesheet">
</head>
<body>
<a href="/">&lt; home</a>
@@ -18,6 +19,11 @@
<form method="post">
<input type="url" placeholder="Feed source" name="feed_source">
<br>
+ <div class="side-by-side-help-container">
+ <input type="text" placeholder="Tags" name="tags">
+ <span class="hover-help" tabindex="0" title="Space separated. Backslashes escape spaces.">🛈</span>
+ </div>
+ <br>
<input type="submit" value="Add">
</form>
</body>
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 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>View Feeds</title>
+ <title>View Feeds | TagRSS</title>
+ <link href="/static/styles/main.css" rel="stylesheet">
</head>
<body>
+ <h1>TagRSS</h1>
+ <nav>
+ <p><a href="/add_feed">Add feed</a></p>
+ </nav>
<table>
- <tr>
- <th>Title</th>
- <th>Date</th>
- </tr>
- % for i, item in enumerate(reversed(items)):
+ <thead>
<tr>
- <td><a href="{{item["link"]}}">{{item["title"]}}</a></td>
- <%
- 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
- %>
- <td>
- {{", updated ".join(dates)}}
- </td>
+ <th>#</th>
+ <th>Title</th>
+ <th>Date</th>
+ <th>Tags</th>
</tr>
- % end
+ </thead>
+ <tbody>
+ % for i, item in enumerate(reversed(items)):
+ <tr>
+ <td>{{i + 1}}</td>
+ <td><a href="{{item["link"]}}">{{item["title"]}}</a></td>
+ <%
+ 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
+ %>
+ <td>
+ {{", updated ".join(dates)}}
+ </td>
+ <td>
+ {{", ".join(item["feed"]["tags"])}}
+ </td>
+ </tr>
+ % end
+ </tbody>
</table>
</body>
</html>