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
1 changed files with 26 additions and 14 deletions

View File

@ -232,8 +232,8 @@ def get_date(filename):
def latest_articles(directory, number): def latest_articles(directory, number):
try: try:
latest_articles = subprocess.check_output(["git", latest_articles = subprocess.check_output(["git",
"ls-files", "ls-files",
directory], directory],
universal_newlines=True) universal_newlines=True)
except: except:
sys.exit("[ERROR] An error occurred when fetching file changes " sys.exit("[ERROR] An error occurred when fetching file changes "
@ -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")
@ -885,7 +897,7 @@ for tag in tags_full_list:
articles_list = ["gen/"+line.replace(".html", ".gen").strip() for line articles_list = ["gen/"+line.replace(".html", ".gen").strip() for line
in tag_gen_fh.readlines()] in tag_gen_fh.readlines()]
articles_list.sort(key=lambda x: (get_date(x)[4:8], get_date(x)[2:4], articles_list.sort(key=lambda x: (get_date(x)[4:8], get_date(x)[2:4],
get_date(x)[:2], get_date(x)[9:]), get_date(x)[:2], get_date(x)[9:]),
reverse=True) reverse=True)
for article in articles_list: for article in articles_list: