diff options
-rw-r--r--[-rwxr-xr-x] | roles/developer/build/files/rss.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/roles/developer/build/files/rss.py b/roles/developer/build/files/rss.py index 7a8f91620..294cad1f2 100755..100644 --- a/roles/developer/build/files/rss.py +++ b/roles/developer/build/files/rss.py @@ -1,6 +1,7 @@ #!/usr/bin/python -tt # -*- coding: utf-8 -*- +from __future__ import print_function import codecs import os import sys @@ -35,7 +36,8 @@ for feed in map(feedparser.parse, FedMag): <div class="row"> """ cnt = 0 - for item in feed["items"][:4]: + # Getting at least 4 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"> @@ -44,13 +46,19 @@ for feed in map(feedparser.parse, FedMag): author, title = item.title.split(':', 1) link = item.links[0]['href'] # Remove image tag from beginning - article_desc = '\n'.join(item.description.split('\n')[1:]) - # remove html tags from description - article_desc = re.sub('<[^<]+?>', '', article_desc) - if len(article_desc) > 140: - article_desc = ' '.join(article_desc.split()[0:25]) + '...' - if not article_desc.startswith('<p>'): - article_desc = '<p>%s</p>' % article_desc + try: + article_desc = '\n'.join(item.description.split('\n')[1:]) + # remove html tags from description + article_desc = re.sub('<[^<]+?>', '', article_desc) + article_desc = re.sub('<', '<', article_desc) + article_desc = re.sub('>', '>', article_desc) + if len(article_desc) > 140: + article_desc = ' '.join(article_desc.split()[0:25]) + '...' + if not article_desc.startswith('<p>'): + article_desc = '<p>%s</p>' % article_desc + except AttributeError: + print ('AttributeError. Going to next item') + continue # we got # Tue, 20 Oct 2015 03:28:42 +0000 # But we expect @@ -73,6 +81,9 @@ for feed in map(feedparser.parse, FedMag): HTML += u""" </div> """ + # Condition if items were collected properly + if int(cnt) > 3: + break HTML += u""" </div> </div> |