remotes/1693045480750635534/spooky-22
Aevann1 2022-07-01 15:11:41 +02:00
parent 5c6ce5e1d7
commit 5bbd14ebd6
2 changed files with 50 additions and 50 deletions

View File

@ -190,7 +190,7 @@ def get_posts(pids, v=None):
blocked, blocked,
blocked.c.user_id == Submission.author_id, blocked.c.user_id == Submission.author_id,
isouter=True isouter=True
).all() ).options(joinedload(Submission.flags), joinedload(Submission.awards), joinedload(Submission.author), joinedload(Submission.author, User.badges)).all()
output = [p[0] for p in query] output = [p[0] for p in query]
for i in range(len(output)): for i in range(len(output)):

View File

@ -8,69 +8,69 @@ from files.helpers.jinja2 import *
from files.__main__ import app from files.__main__ import app
@app.get('/rss') # @app.get('/rss')
@app.get('/feed') # @app.get('/feed')
@app.get('/rss/<sort>/<t>') # @app.get('/rss/<sort>/<t>')
def feeds_user(sort='hot', t='all'): # def feeds_user(sort='hot', t='all'):
try: page = max(int(request.values.get("page", 1)), 1) # try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1 # except: page = 1
ids, next_exists = frontlist( # ids, next_exists = frontlist(
sort=sort, # sort=sort,
page=page, # page=page,
t=t, # t=t,
v=None, # v=None,
) # )
posts = get_posts(ids) # posts = get_posts(ids)
domain = environ.get("DOMAIN").strip() # domain = environ.get("DOMAIN").strip()
doc, tag, text = Doc().tagtext() # doc, tag, text = Doc().tagtext()
with tag("feed", ("xmlns:media","http://search.yahoo.com/mrss/"), xmlns="http://www.w3.org/2005/Atom",): # with tag("feed", ("xmlns:media","http://search.yahoo.com/mrss/"), xmlns="http://www.w3.org/2005/Atom",):
with tag("title", type="text"): # with tag("title", type="text"):
text(f"{sort} posts from {domain}") # text(f"{sort} posts from {domain}")
with tag("id"): # with tag("id"):
text(SITE_FULL + request.full_path) # text(SITE_FULL + request.full_path)
with tag("updated"): # with tag("updated"):
text(datetime.now().isoformat()+"Z") # text(datetime.now().isoformat()+"Z")
doc.stag("link", rel="self", type="application/atom+xml", href=SITE_FULL + request.full_path) # 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) # doc.stag("link", rel="alternate", type="text/html", href=SITE_FULL)
for post in posts: # for post in posts:
with tag("entry", ("xml:base", SITE_FULL + request.full_path)): # with tag("entry", ("xml:base", SITE_FULL + request.full_path)):
with tag("title", type="html"): # with tag("title", type="html"):
text(post.realtitle(None)) # text(post.realtitle(None))
with tag("id"): # with tag("id"):
text(post.permalink) # text(post.permalink)
with tag("updated"): # with tag("updated"):
if (post.edited_utc): # if (post.edited_utc):
text(datetime.utcfromtimestamp(post.edited_utc).isoformat()+"Z") # text(datetime.utcfromtimestamp(post.edited_utc).isoformat()+"Z")
else: # else:
text(datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z") # text(datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z")
with tag("published"): # with tag("published"):
text(datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z") # text(datetime.utcfromtimestamp(post.created_utc).isoformat()+"Z")
with tag("author"): # with tag("author"):
with tag("name"): # with tag("name"):
text(post.author_name) # text(post.author_name)
with tag("uri"): # with tag("uri"):
text(f'/@{post.author_name}') # text(f'/@{post.author_name}')
doc.stag("link", href=post.permalink) # doc.stag("link", href=post.permalink)
image_url = post.thumb_url or post.embed_url or post.url # image_url = post.thumb_url or post.embed_url or post.url
doc.stag("media:thumbnail", url=image_url) # doc.stag("media:thumbnail", url=image_url)
if len(post.body_html): # if len(post.body_html):
with tag("content", type="html"): # with tag("content", type="html"):
doc.cdata(f'''<img alt="{post.realtitle(None)}" loading="lazy" src="{image_url}"><br>{post.realbody(None)}''') # doc.cdata(f'''<img alt="{post.realtitle(None)}" loading="lazy" src="{image_url}"><br>{post.realbody(None)}''')
return Response( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ doc.getvalue(), mimetype="application/xml") # return Response( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ doc.getvalue(), mimetype="application/xml")