2022-12-22 21:56:29 +00:00
|
|
|
import datetime
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
from yattag import Doc
|
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.get import *
|
|
|
|
from files.routes.wrappers import *
|
|
|
|
|
|
|
|
from .front import frontlist
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.__main__ import app
|
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
@app.get('/rss')
|
|
|
|
@app.get('/feed')
|
|
|
|
@app.get('/rss/<sort>/<t>')
|
|
|
|
def feeds_user(sort='hot', t='all'):
|
|
|
|
|
|
|
|
try: page = max(int(request.values.get("page", 1)), 1)
|
|
|
|
except: page = 1
|
|
|
|
|
|
|
|
ids, next_exists = frontlist(
|
|
|
|
sort=sort,
|
|
|
|
page=page,
|
|
|
|
t=t,
|
|
|
|
v=None,
|
|
|
|
)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
posts = get_posts(ids)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
doc, tag, text = Doc().tagtext()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-09 03:49:50 +00:00
|
|
|
with tag("feed", ("xmlns:media","http://search.yahoo.com/mrss/"), xmlns="http://www.w3.org/2005/Atom",):
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("title", type="text"):
|
|
|
|
text(f"{sort} posts from {SITE}")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("id"):
|
|
|
|
text(SITE_FULL + request.full_path)
|
|
|
|
with tag("updated"):
|
2022-12-22 21:26:46 +00:00
|
|
|
text(datetime.datetime.now().isoformat()+"Z")
|
2022-07-08 16:21:20 +00:00
|
|
|
doc.stag("link", rel="self", type="application/atom+xml", href=SITE_FULL + request.full_path)
|
|
|
|
doc.stag("link", rel="alternate", type="text/html", href=SITE_FULL)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
for post in posts:
|
|
|
|
with tag("entry", ("xml:base", SITE_FULL + request.full_path)):
|
|
|
|
with tag("title", type="html"):
|
|
|
|
text(post.realtitle(None))
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("id"):
|
|
|
|
text(post.permalink)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("updated"):
|
|
|
|
if (post.edited_utc):
|
2022-12-22 21:56:29 +00:00
|
|
|
text(datetime.datetime.utcfromtimestamp(post.edited_utc).isoformat()+"Z")
|
2022-07-08 16:21:20 +00:00
|
|
|
else:
|
2022-12-22 21:56:29 +00:00
|
|
|
text(datetime.datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("published"):
|
2022-12-22 21:56:29 +00:00
|
|
|
text(datetime.datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z")
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
with tag("author"):
|
|
|
|
with tag("name"):
|
|
|
|
text(post.author_name)
|
|
|
|
with tag("uri"):
|
|
|
|
text(f'/@{post.author_name}')
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
doc.stag("link", href=post.permalink)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
image_url = post.thumb_url or post.embed_url or post.url
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
doc.stag("media:thumbnail", url=image_url)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-08 16:21:20 +00:00
|
|
|
if len(post.body_html):
|
|
|
|
with tag("content", type="html"):
|
|
|
|
doc.cdata(f'''<img alt="{post.realtitle(None)}" loading="lazy" src="{image_url}"><br>{post.realbody(None)}''')
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-08-17 20:30:07 +00:00
|
|
|
return Response("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ doc.getvalue(), mimetype="application/xml")
|