From 46d4f104336dccb2e7dcc5b99162006a910d7576 Mon Sep 17 00:00:00 2001 From: Ben Cotton Date: Wed, 19 Aug 2020 16:06:24 -0400 Subject: [PATCH] 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 --- roles/developer/build/files/rss.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/roles/developer/build/files/rss.py b/roles/developer/build/files/rss.py index 294cad1f27..ce0f575594 100644 --- a/roles/developer/build/files/rss.py +++ b/roles/developer/build/files/rss.py @@ -36,14 +36,20 @@ for feed in map(feedparser.parse, FedMag):
""" 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"""
""" item.title = item.title.replace("&", "&") - author, title = item.title.split(':', 1) + # 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: