From 4c712c2e209017f5cf7c4e02cf6bd66ea457fc6d Mon Sep 17 00:00:00 2001 From: maste9 Date: Sun, 22 Mar 2015 14:26:52 +0100 Subject: [PATCH] Localized the time formats with locale module and corrected some hard coded formats to %x. After correcting dates in regard to this in the articles' txt-files everything worked wonderfully. --- picoblogger/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/picoblogger/main.py b/picoblogger/main.py index 467086c..1fd576d 100755 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -1,9 +1,10 @@ #!/usr/bin/python3 -import os,re,time,getpass,subprocess,markdown +import os,re,locale,time,getpass,subprocess,markdown from string import Template from argparse import ArgumentParser + ######################################## # UI - check for arguments and options # ######################################## @@ -157,6 +158,8 @@ except: print("Couldn't parse localization file (%s)."%l10nconfpath) raise +locale.setlocale(locale.LC_ALL,os.environ['LANG']) +# print(time.strftime("%x",time.localtime())) ######################## # Templating functions # @@ -262,7 +265,7 @@ def recent_articles(amount): for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]: article = (parse_article(os.path.join(artDir, name + ".txt"))) # Bring articles into chronological order - t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S")) + t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S")) articles_dict[str(t)] = article dates_of_creation = [float(value) for value in articles_dict.keys()] dates_of_creation.sort(key=None,reverse=True) @@ -280,7 +283,7 @@ def archive_articles(): for article in articles: aName = article["FILENAME"] aPath = os.path.join(article["PATH"], aName) - aDate = time.strptime(article["DATE"],"%m/%d/%y") + aDate = time.strptime(article["DATE"],"%x") aMonth = aDate.tm_mon aYear = aDate.tm_year @@ -330,7 +333,7 @@ def list_articles(folder): for name in [os.path.splitext(item)[0] for item in os.listdir(folder) if not "~" in item]: article = (parse_article(os.path.join(folder, name + ".txt"))) # Bring articles into chronological order - t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S")) + t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S")) articles_dict[str(t)] = article return articles_dict