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
13
roles/developer/build/files/rss.py
Executable file → Normal file
13
roles/developer/build/files/rss.py
Executable file → Normal file
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python -tt
|
#!/usr/bin/python -tt
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -35,7 +36,8 @@ for feed in map(feedparser.parse, FedMag):
|
||||||
<div class="row">
|
<div class="row">
|
||||||
"""
|
"""
|
||||||
cnt = 0
|
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:
|
if int(cnt) % 2 == 0:
|
||||||
HTML += u"""
|
HTML += u"""
|
||||||
<div class="col-sm-6 blog-headlines">
|
<div class="col-sm-6 blog-headlines">
|
||||||
|
@ -44,13 +46,19 @@ for feed in map(feedparser.parse, FedMag):
|
||||||
author, title = item.title.split(':', 1)
|
author, title = item.title.split(':', 1)
|
||||||
link = item.links[0]['href']
|
link = item.links[0]['href']
|
||||||
# Remove image tag from beginning
|
# Remove image tag from beginning
|
||||||
|
try:
|
||||||
article_desc = '\n'.join(item.description.split('\n')[1:])
|
article_desc = '\n'.join(item.description.split('\n')[1:])
|
||||||
# remove html tags from description
|
# remove html tags from description
|
||||||
article_desc = re.sub('<[^<]+?>', '', article_desc)
|
article_desc = re.sub('<[^<]+?>', '', article_desc)
|
||||||
|
article_desc = re.sub('<', '<', article_desc)
|
||||||
|
article_desc = re.sub('>', '>', article_desc)
|
||||||
if len(article_desc) > 140:
|
if len(article_desc) > 140:
|
||||||
article_desc = ' '.join(article_desc.split()[0:25]) + '...'
|
article_desc = ' '.join(article_desc.split()[0:25]) + '...'
|
||||||
if not article_desc.startswith('<p>'):
|
if not article_desc.startswith('<p>'):
|
||||||
article_desc = '<p>%s</p>' % article_desc
|
article_desc = '<p>%s</p>' % article_desc
|
||||||
|
except AttributeError:
|
||||||
|
print ('AttributeError. Going to next item')
|
||||||
|
continue
|
||||||
# we got
|
# we got
|
||||||
# Tue, 20 Oct 2015 03:28:42 +0000
|
# Tue, 20 Oct 2015 03:28:42 +0000
|
||||||
# But we expect
|
# But we expect
|
||||||
|
@ -73,6 +81,9 @@ for feed in map(feedparser.parse, FedMag):
|
||||||
HTML += u"""
|
HTML += u"""
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
# Condition if items were collected properly
|
||||||
|
if int(cnt) > 3:
|
||||||
|
break
|
||||||
HTML += u"""
|
HTML += u"""
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue