Update RSS feed to make it valid

This commit is contained in:
Phyks 2014-07-12 15:33:27 +02:00
parent dc9e9a10af
commit 0f15a2b471

View File

@ -283,6 +283,10 @@ def get_text_rss(content):
def remove_tags(html): def remove_tags(html):
return ''.join(BeautifulSoup(html).findAll(text=True)) return ''.join(BeautifulSoup(html).findAll(text=True))
def truncate(text, length=100):
return text[:text.find('.', length) - 1] + ""
# Set locale # Set locale
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -812,19 +816,27 @@ for i, article in enumerate(["gen/"+x[4:-5]+".gen" for x in last_articles]):
"%d%m%Y-%H%M") "%d%m%Y-%H%M")
.timetuple())))) .timetuple()))))
rss += ("\t\t<item>\n" rss += ("\t\t<item>\n" +
"\t\t\t<title>"+remove_tags(title)+"</title>\n" "\t\t\t<title>"+remove_tags(title)+"</title>\n" +
"\t\t\t<link>"+params["PROTOCOL"]+params["BLOG_URL"]+"/" + "\t\t\t<link>"+params["PROTOCOL"]+params["BLOG_URL"]+"/" +
article[4:-4]+".html</link>\n" + article[4:-4]+".html</link>\n" +
"\t\t\t<guid isPermaLink=\"false\">" + "\t\t\t<guid isPermaLink=\"true\">" +
params["PROTOCOL"] + params["BLOG_URL"]+"/"+article[4:-4]+"</guid>\n" params["PROTOCOL"] + params["BLOG_URL"]+"/"+article[4:-4]+".html</guid>\n"
"\t\t\t<description><![CDATA[" + # Apply remove_tags twice to also remove tags in @title and so
replace_tags(get_text_rss(content), search_list, replace_list) + "\t\t\t<description>" + truncate(remove_tags(remove_tags(replace_tags(get_text_rss(content),
"]]></description>\n" search_list,
"\t\t\t<pubDate>"+date_rss+"</pubDate>\n" replace_list)))) +
"\t\t\t<category>" + "</description>\n" +
', '.join([i.strip() for i in tags.split(",")])+"</category>\n" "\t\t\t<content:encoded><![CDATA[" +
"\t\t\t<author>"+params["WEBMASTER"]+"</author>\n" replace_tags(get_text_rss(content),
search_list,
replace_list).replace(params['BLOG_URL'],
params['BLOG_URL_RSS']) +
"]]></content:encoded>\n" +
"\t\t\t<pubDate>"+date_rss+"</pubDate>\n" +
("\n".join(["\t\t\t<category>" + i.strip() + "</category>"
for i in tags.split(",")]))+"\n" +
"\t\t\t<author>"+params["WEBMASTER"]+"</author>\n" +
"\t\t</item>\n") "\t\t</item>\n")