Add fixes to developer rss.py from ticket 4978
This commit is contained in:
parent
2215586ac1
commit
5ea849a5bd
1 changed files with 19 additions and 8 deletions
27
roles/developer/build/files/rss.py
Executable file → Normal file
27
roles/developer/build/files/rss.py
Executable file → Normal file
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue