From 69a356d177ad98941502b621754d011383e160d9 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Thu, 22 Jun 2023 07:47:44 +0530 Subject: Initial commit --- .gitignore | 1 + requirements.txt | 7 ++++++ serve.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/add_feed.tpl | 24 ++++++++++++++++++ views/index.tpl | 33 ++++++++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100755 serve.py create mode 100644 views/add_feed.tpl create mode 100644 views/index.tpl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f21b54 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/venv/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..425cad0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +bottle==0.12.25 +feedparser==6.0.10 +gevent==22.10.2 +greenlet==2.0.2 +sgmllib3k==1.0.0 +zope.event==4.6 +zope.interface==6.0 diff --git a/serve.py b/serve.py new file mode 100755 index 0000000..7e07fdc --- /dev/null +++ b/serve.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +from gevent import monkey + +monkey.patch_all() +import bottle +import feedparser +import gevent.lock + +import argparse +import datetime + +parser = argparse.ArgumentParser() +parser.add_argument("host", nargs="?", default="localhost") +parser.add_argument("-p", "--port", default=8000, type=int) +args = parser.parse_args() + +feeds_lock = gevent.lock.RLock() +feeds = {} + +feed_items_lock = gevent.lock.RLock() +feed_items = [] + +def store_feed(feed_url: str): + ... + + +@bottle.route("/") +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") + + +@bottle.post("/add_feed") +def add_feed_effect(): + feed_source = bottle.request.forms.get("feed_source") + already_present: bool = False + with feeds_lock: + if feed_source not in feeds: + feeds[feed_source] = {} + 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") + except AttributeError: + date_published = None + try: + date_updated = datetime.datetime(*(entry.updated_parsed[0:6])).strftime("%x %X") + 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(): + ... + + +bottle.run(host=args.host, port=args.port, server="gevent") diff --git a/views/add_feed.tpl b/views/add_feed.tpl new file mode 100644 index 0000000..bac78b0 --- /dev/null +++ b/views/add_feed.tpl @@ -0,0 +1,24 @@ + + + + + + Add Feed + + + < home + % if not get("already_present", False): + % if get("after_add", False): +

Added feed {{feed_source}}

+ % end + % else: +

Feed {{feed_source}} was already added; no changes made.

+ % end +

Add a feed

+
+ +
+ +
+ + diff --git a/views/index.tpl b/views/index.tpl new file mode 100644 index 0000000..b08ce0f --- /dev/null +++ b/views/index.tpl @@ -0,0 +1,33 @@ + + + + + + View Feeds + + + + + + + + % 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)}} +
+ + -- cgit v1.2.3-57-g22cb