From 62e460dc98750620ed85061476f54ae725f230f6 Mon Sep 17 00:00:00 2001 From: maste9 Date: Mon, 9 Mar 2015 21:15:43 +0100 Subject: [PATCH] Working on archive. Articles should be moved to archive folder. --- picoblogger/main.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/picoblogger/main.py b/picoblogger/main.py index 9acec39..24bfc1d 100755 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -82,6 +82,9 @@ draftDir = os.path.join(blog_dir,"drafts") # path to articles articleDir = os.path.join(blog_dir,"articles") +# path to archive +archiveDir = os.path.join(blog_dir,"archive") + # paths to configs pbconfpath = os.path.join("/","etc","picoblogger","pb.conf") # global config blogconfpath = os.path.join(blog_dir,"pb.conf") # local config @@ -129,6 +132,7 @@ try: dateFormat = blogconf['BLOG_DATE_FORMAT'] timeFormat = blogconf['BLOG_TIME_FORMAT'] amountRecent = int(blogconf['RECENT_AMOUNT']) + notToArchive = blogconf['BLOG_CURRENT_ARTICLES'] except: print("Couldn't parse blog's local configuration (%s)."%blogconfpath) @@ -254,6 +258,11 @@ def recent_articles(amount): return joined_html +def archive_articles(notToArchive): + articles= [item for os.listdir(artDir) if not "\~" in item] + for i in range(notToArchive,): + + os.replace(draft, article) def update_blog(subsection): # Joins config defined variables into templates @@ -261,8 +270,6 @@ def update_blog(subsection): tplIndex = os.path.join(tplDir,"index.htm") blogIndex = os.path.join(blog_dir,"index.html") - blogArchive = os.path.join(blog_dir,"archive.html") - tpl = Template(open(tplIndex,'r').read()) sNAV = open(os.path.join(tplDir,"nav.htm")).read() @@ -270,7 +277,6 @@ def update_blog(subsection): # sMAIN = open(os.path.join(tplDir,"main.htm")).read() # sMAIN = Template(sMAIN).safe_substitute(join_articles()) sMAIN = join_articles() - sARCHIVE = join_articles() sASIDE = open(os.path.join(tplDir,"aside.htm")).read() sRECENT = open(os.path.join(tplDir,"recent.htm")).read() @@ -311,16 +317,6 @@ def update_blog(subsection): with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f: print(tmpIndex, file=f) - tplSub['TEMPLATE_MAIN'] = sARCHIVE - - tmpIndex = Template(tmpIndex).safe_substitute(tplSub) - - with open(blogArchive,"w", encoding=l10nconf['BLOG_CHARSET']) as f: - print(tmpIndex, file=f) - - - - # def article_to_html(name): # article = os.path.join(blog_dir,"articles",name + ".txt")