From 6bc5fe9aba0cac5aa3cce5dce1f2862731de85cc Mon Sep 17 00:00:00 2001 From: doesnmisclown Date: Sun, 13 Aug 2023 09:37:25 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.ini.example | 8 ++++++++ rss.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 config.ini.example create mode 100644 rss.py diff --git a/config.ini.example b/config.ini.example new file mode 100644 index 0000000..242f09b --- /dev/null +++ b/config.ini.example @@ -0,0 +1,8 @@ +[general] +last_run = PASTE_TIMESTAMP +token = MATRIX_TOKEN + +[feed.myfeed] +title = Feed Title +url = FEED_URL +room_id = ROOM_ID \ No newline at end of file diff --git a/rss.py b/rss.py new file mode 100644 index 0000000..f6445b9 --- /dev/null +++ b/rss.py @@ -0,0 +1,34 @@ +import xml.etree.ElementTree as ET +from urllib.request import urlopen, Request +from time import time +from datetime import datetime +from configparser import ConfigParser +from uuid import uuid4 as uuid +import json +config = ConfigParser() +config.read("config.ini") +now = int(config["general"]["last_run"]) +for f in config.sections(): + if not "feed." in f: continue + with urlopen(config[f]["url"]) as r: + r = ET.parse(r) + for i in r.findall("./channel/item"): + date = i.find("pubDate").text + date = datetime.strptime(date, "%a, %d %b %Y %H:%M:%S %z") + date = datetime.timestamp(date) + date = int(date) + if date > now: + title = i.find("title").text + link = i.find("link").text + data = json.dumps( + dict(msgtype="m.text", + body=f"[{title}]({link})", + formatted_body=f'{title}', + format="org.matrix.custom.html" + )) + req = Request(f"https://fb.doesnm.cc/_matrix/client/v3/rooms/{config[f]['room_id']}/send/m.room.message/{uuid()}?access_token={config['general']['token']}",data.encode("ascii"),method="PUT") # TODO: homeserver config lol + with urlopen(req) as r: + pass + config['general']['last_run'] = str(int(time())) + with open("config.ini","w") as f: + config.write(f) \ No newline at end of file