From 0f15a2b47151041d4c9ca86daedb23803377f741 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sat, 12 Jul 2014 15:33:27 +0200 Subject: [PATCH] Update RSS feed to make it valid --- pre-commit.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/pre-commit.py b/pre-commit.py index f2c2c3b..b324453 100755 --- a/pre-commit.py +++ b/pre-commit.py @@ -232,8 +232,8 @@ def get_date(filename): def latest_articles(directory, number): try: latest_articles = subprocess.check_output(["git", - "ls-files", - directory], + "ls-files", + directory], universal_newlines=True) except: sys.exit("[ERROR] An error occurred when fetching file changes " @@ -283,6 +283,10 @@ def get_text_rss(content): def remove_tags(html): return ''.join(BeautifulSoup(html).findAll(text=True)) + +def truncate(text, length=100): + return text[:text.find('.', length) - 1] + "…" + # Set locale 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") .timetuple())))) - rss += ("\t\t\n" - "\t\t\t"+remove_tags(title)+"\n" + rss += ("\t\t\n" + + "\t\t\t"+remove_tags(title)+"\n" + "\t\t\t"+params["PROTOCOL"]+params["BLOG_URL"]+"/" + article[4:-4]+".html\n" + - "\t\t\t" + - params["PROTOCOL"] + params["BLOG_URL"]+"/"+article[4:-4]+"\n" - "\t\t\t\n" - "\t\t\t"+date_rss+"\n" - "\t\t\t" + - ', '.join([i.strip() for i in tags.split(",")])+"\n" - "\t\t\t"+params["WEBMASTER"]+"\n" + "\t\t\t" + + params["PROTOCOL"] + params["BLOG_URL"]+"/"+article[4:-4]+".html\n" + # Apply remove_tags twice to also remove tags in @title and so + "\t\t\t" + truncate(remove_tags(remove_tags(replace_tags(get_text_rss(content), + search_list, + replace_list)))) + + "\n" + + "\t\t\t\n" + + "\t\t\t"+date_rss+"\n" + + ("\n".join(["\t\t\t" + i.strip() + "" + for i in tags.split(",")]))+"\n" + + "\t\t\t"+params["WEBMASTER"]+"\n" + "\t\t\n") @@ -885,7 +897,7 @@ for tag in tags_full_list: articles_list = ["gen/"+line.replace(".html", ".gen").strip() for line in tag_gen_fh.readlines()] 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) for article in articles_list: