Загрузить файлы в «/»

This commit is contained in:
doesnmisclown 2023-08-13 09:37:25 +00:00
parent 0a927d0fed
commit 6bc5fe9aba
2 changed files with 42 additions and 0 deletions

8
config.ini.example Normal file
View File

@ -0,0 +1,8 @@
[general]
last_run = PASTE_TIMESTAMP
token = MATRIX_TOKEN
[feed.myfeed]
title = Feed Title
url = FEED_URL
room_id = ROOM_ID

34
rss.py Normal file
View File

@ -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'<a href="{link}">{title}</a>',
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)