Fix handling of title-less Planet posts

Some platforms can give us a post without a title. When that happens,
Planet's RSS feed title is "$author" instead of "$author.title", which
causes our split to blow up. Instead, we check to see if there is a ':',
and if so split like normal. If not, explicitly set the title to
"(untitled post)" in order for it to still render.

While I'm at it, update a comment so that it reflects what the code is
actually doing.

Fixes #9251

Signed-off-by: Ben Cotton <bcotton@fedoraproject.org>
This commit is contained in:
Ben Cotton 2020-08-19 16:06:24 -04:00 committed by pingou
parent 5ae12fbb83
commit 46d4f10433

View file

@ -36,14 +36,20 @@ for feed in map(feedparser.parse, FedMag):
<div class="row">
"""
cnt = 0
# Getting at least 4 items in case of some python exceptions.
# Getting at least 6 items in case of some python exceptions.
for item in feed["items"][:6]:
if int(cnt) % 2 == 0:
HTML += u"""
<div class="col-sm-6 blog-headlines">
"""
item.title = item.title.replace("&", "&#38;")
# If a blog post doesn't have a title for some reason, it breaks the way
# we try to parse out the author and title. Let's say it's untitled in
# order for it to appear on the page without breaking the script.
if ":" in item.title:
author, title = item.title.split(':', 1)
else:
author, title = item.title, "(untitled post)"
link = item.links[0]['href']
# Remove image tag from beginning
try: