From ecfab3c7b10aa9da3d9c6bcd1f0dae747c41ccfe Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 27 Oct 2013 14:01:24 +0100 Subject: [PATCH] Bug correction + RSS feed code completed --- pre-commit.py | 71 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/pre-commit.py b/pre-commit.py index 2a555e9..2ac5b65 100755 --- a/pre-commit.py +++ b/pre-commit.py @@ -28,6 +28,7 @@ import re import locale from time import gmtime, strftime, mktime +from bs4 import BeautifulSoup # ========= @@ -134,6 +135,16 @@ def replace_tags(article, search_list, replace_list): return return_string +# Return text in
for rss description +# ======================================================== +def get_text_rss(content): + soup = BeautifulSoup(content) + date = soup.find(attrs={'class': 'date'}) + date.extract() + title = soup.find(attrs={'class': 'article_title'}) + title.extract() + return str(soup.div) + # Set locale locale.setlocale(locale.LC_ALL, '') @@ -175,12 +186,18 @@ try: if line.strip() == "" or line.strip().startswith("#"): continue option, value = line.split("=", 1) + option = option.strip() + if option == "SEARCH": search_list = [i.strip() for i in value.split(",")] elif option == "REPLACE": replace_list = [i.strip() for i in value.split(",")] elif option == "MONTHS": months = [i.strip() for i in value.split(",")] + elif option == "IGNORE_FILES": + params["IGNORE_FILES"] = [i.strip() for i in value.split(",")] + elif option == "BLOG_URL": + params["BLOG_URL"] = value.strip(" \n\t\r/") else: params[option.strip()] = value.strip() @@ -190,6 +207,7 @@ except IOError: "parameters. Does such a file exist ? See doc for more info " "on this file.") +print("[INFO] Blog url is "+params["BLOG_URL"]+".") # Fill lists for modified, deleted and added files modified_files = [] @@ -227,9 +245,12 @@ if not force_regen: else: sys.exit("[ERROR] An error occurred when running git diff.") else: - shutil.rmtree("blog/") - shutil.rmtree("gen/") - added_files = list_directory("raw") + try: + shutil.rmtree("blog/") + shutil.rmtree("gen/") + added_files = list_directory("raw") + except FileNotFoundError: + pass if not added_files and not modified_files and not deleted_files: sys.exit("[ERROR] Nothing to do... Did you add new files with " @@ -239,7 +260,8 @@ if not added_files and not modified_files and not deleted_files: for filename in list(added_files): direct_copy = False - if not filename.startswith("raw/"): + if (not filename.startswith("raw/") or filename.endswith("~") or + filename in params["IGNORE_FILES"]): added_files.remove(filename) continue @@ -277,7 +299,8 @@ for filename in list(added_files): for filename in list(modified_files): direct_copy = False - if not filename.startswith("raw/"): + if (not filename.startswith("raw/") or filename.endswith("~") + or filename in params["IGNORE_FILES"]): modified_files.remove(filename) continue try: @@ -312,7 +335,8 @@ for filename in list(modified_files): for filename in list(deleted_files): direct_copy = False - if not filename.startswith("raw/"): + if (not filename.startswith("raw/") or filename.endswith("~") or + filename in params["IGNORE_FILES"]): deleted_files.remove(filename) continue @@ -401,8 +425,8 @@ for filename in modified_files: print("[INFO] (TAGS) No more article with tag " + tag[8:-4]+", deleting it.") except FileNotFoundError: - print("[INFO] (TAGS) "+tag+" was found to be empty " - "but there was an error during deletion. " + print("[INFO] (TAGS) "+tag+" was found to be empty" + " but there was an error during deletion. " "You should check manually.") tags.remove(tag_file[9:]) @@ -518,7 +542,9 @@ for filename in added_files+modified_files: "\t\t

"+month_aside+"

\n" "\t\n" "\t
\n" - "\t\t

"+title+"

\n" + "\t\t

"+title+"

\n" "\t\t"+article+"\n" "\t\t

"+date_readable+"

\n" "\t
\n" @@ -542,7 +568,7 @@ except IOError: sys.exit("[ERROR] Unable to open raw/header.html file.") header = header.replace("@tags", tags_header, 1) -header = header.replace("@blog_url", params["BLOG_URL"], 1) +header = header.replace("@blog_url", params["BLOG_URL"]) articles_header = "" +articles_header += ("

"+"Archives

") header = header.replace("@articles", articles_header, 1) try: @@ -637,7 +664,8 @@ except IOError: # Finishing index gen index = (header.replace("@title", params["BLOG_TITLE"], 1) + - articles_index + footer) + articles_index + "

Archives

"+footer) try: with open("blog/index.html", "w") as index_fh: @@ -759,7 +787,8 @@ archives = header.replace("@title", params["BLOG_TITLE"]+" - Archives", 1) years_list = os.listdir("blog/") years_list.sort(reverse=True) -archives += "
" archives += footer try: