From 4263748b54ecd6177aab12dd76b6c19e4af9578e Mon Sep 17 00:00:00 2001 From: Vinay Deshmukh Date: Jul 17 2020 12:14:02 +0000 Subject: Take the first enclosure of type 'image/jpg' to use as thumbnail for start.fedoraprojectorg This commit iterates over the enclosure tags of each article, and uses the first one whose `type` attribute is 'image/jpg'. In the case no enclosure with this criteria is found, it will use the last enclosure in the list. --- diff --git a/start.fedoraproject.org/build/magfeed.py b/start.fedoraproject.org/build/magfeed.py index ced70b2..1f241f7 100644 --- a/start.fedoraproject.org/build/magfeed.py +++ b/start.fedoraproject.org/build/magfeed.py @@ -20,6 +20,11 @@ for feed in map(feedparser.parse, FedMag): # removing '[...]' from the summary, so its cleaner summary = item.summary.rstrip(' […]').replace("’", "'").replace("’", "'") item.title = item.title.replace("&", "&") + # find the first image enclosure + for image_enclosure in item.enclosures: + if image_enclosure['type'] == 'image/jpg': + break + html += """ - """ % (item.updated.split()[2], item.updated.split()[1], item.enclosures[0].href.replace("&", "&"), item.links[0]['href'], item.title, + """ % (item.updated.split()[2], item.updated.split()[1], image_enclosure.href.replace("&", "&"), item.links[0]['href'], item.title, item.slash_comments, summary, item.links[0]['href']) #print item.content #break