Commit Diff


commit - bebc3eb3a50928d8ee9feaa7892ed628cd20fcb7
commit + 098f1899fbb8d4842c1f946ac7c80420ec046757
blob - /dev/null
blob + 21900dfa34c266503e86727aac0e925a1f9d780c (mode 644)
--- /dev/null
+++ LICENSE
@@ -0,0 +1,5 @@
+Copyright (C) 2023 by @continue@honk.any-key.press <email:continue@to.any-key.press>
+
+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
blob - /dev/null
blob + 315b058eba05fe587d21dedd7884fa05de10df06 (mode 644)
--- /dev/null
+++ ronk.py
@@ -0,0 +1,46 @@
+import dbm
+import argparse
+import xml.etree.ElementTree as ET
+
+import requests
+
+
+def format_item(item):
+    link = item.get('link')
+    p = ET.Element('p')
+    a = ET.SubElement(p, 'a')
+    a.attrib.update(href=link)
+    a.text = item.get('title') or link
+    return ET.tostring(p, encoding="unicode") + item.get("description", "").strip()
+
+
+def main(db, rss_url, server_url, token):
+    resp = requests.get(rss_url)
+    resp.raise_for_status()
+
+    collected = []
+    for root_child in ET.fromstring(resp.text):
+        if root_child.tag == "channel":
+            for channel_child in root_child:
+                if channel_child.tag == 'item':
+                    collected.insert(0, {i.tag: i.text for i in channel_child})
+            break
+
+    honk_server = requests.Session()
+    for item in collected:
+        key = item.get('link')
+        if key:
+            params = dict(action="honk", token=token, noise=format_item(item), format="html")
+            honk_server.post(server_url, params=params)
+            db[key] = "1"
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(prog='ronk', description='RSS-to-honk bot')
+    parser.add_argument('--db', required=True, help='path to local database file')
+    parser.add_argument('--rss', required=True, help='source RSS URL')
+    parser.add_argument('--honk', required=True, help='destination honk server URL')
+    parser.add_argument('--token', required=True, help='user token, see honk(3)')
+    args = parser.parse_args()
+    with dbm.open(args.db, 'c') as db:
+        main(db, args.rss, args.honk, args.token)