2021-07-21 01:12:26 +00:00
|
|
|
import html
|
|
|
|
from .front import frontlist
|
|
|
|
from datetime import datetime
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.helpers.jinja2 import full_link
|
|
|
|
from files.helpers.get import *
|
2021-07-21 01:12:26 +00:00
|
|
|
from yattag import Doc
|
|
|
|
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.__main__ import app
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get('/rss/<sort>/<t>')
|
2021-07-21 01:12:26 +00:00
|
|
|
def feeds_user(sort='hot', t='all'):
|
|
|
|
|
|
|
|
page = int(request.args.get("page", 1))
|
|
|
|
|
2021-08-14 21:33:41 +00:00
|
|
|
ids, next_exists = frontlist(
|
2021-07-21 01:12:26 +00:00
|
|
|
sort=sort,
|
|
|
|
page=page,
|
|
|
|
t=t,
|
|
|
|
v=None,
|
2021-07-28 10:57:26 +00:00
|
|
|
)
|
2021-08-14 21:33:41 +00:00
|
|
|
|
|
|
|
posts = get_posts(ids)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-19 05:49:50 +00:00
|
|
|
domain = environ.get("DOMAIN").strip()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
doc, tag, text = Doc().tagtext()
|
|
|
|
|
|
|
|
with tag("feed", ("xmlns:media","http://search.yahoo.com/mrss/"), xmlns="http://www.w3.org/2005/Atom",):
|
|
|
|
with tag("title", type="text"):
|
|
|
|
text(f"{sort} posts from {domain}")
|
|
|
|
|
|
|
|
doc.stag("link", href=request.url)
|
|
|
|
doc.stag("link", href=request.url_root)
|
|
|
|
|
|
|
|
for post in posts:
|
|
|
|
#print("POST IMAGE "+ str( post.is_image ))
|
|
|
|
with tag("entry", ("xml:base", request.url)):
|
|
|
|
with tag("title", type="text"):
|
|
|
|
text(post.title)
|
|
|
|
|
|
|
|
with tag("id"):
|
|
|
|
text(post.fullname)
|
|
|
|
|
|
|
|
if (post.edited_utc > 0):
|
|
|
|
with tag("updated"):
|
|
|
|
text(datetime.utcfromtimestamp(post.edited_utc).isoformat())
|
|
|
|
|
|
|
|
with tag("published"):
|
|
|
|
text(datetime.utcfromtimestamp(post.created_utc).isoformat())
|
|
|
|
|
|
|
|
doc.stag("link", href=post.url)
|
|
|
|
|
|
|
|
with tag("author"):
|
|
|
|
with tag("name"):
|
|
|
|
text(post.author.username)
|
|
|
|
with tag("uri"):
|
2021-08-02 15:05:46 +00:00
|
|
|
text(f'https://{site}/@{post.author.username}')
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
doc.stag("link", href=full_link(post.permalink))
|
|
|
|
|
|
|
|
image_url = post.thumb_url or post.embed_url or post.url
|
|
|
|
|
|
|
|
doc.stag("media:thumbnail", url=image_url)
|
|
|
|
|
|
|
|
if len(post.body_html) > 0:
|
|
|
|
with tag("content", type="html"):
|
2021-09-03 14:09:31 +00:00
|
|
|
text(html.escape(f'<img loading="lazy" src={image_url}/><br/>{post.body_html}'))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
return Response( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ doc.getvalue(), mimetype="application/xml")
|