diff --git a/picoblogger/blog/archive.html b/picoblogger/blog/archive.html deleted file mode 100644 index 47a512c..0000000 --- a/picoblogger/blog/archive.html +++ /dev/null @@ -1,127 +0,0 @@ - - - - Mein Blog - - - - - - - - - - - - - - -
-

Mein Blog

Meine Worte, Meine Meinung ...

-
- -
-
-

Artikel

-
-
-

Das ist der zweite Artikel

-
-
Autor
homer77
-
Erstellt am
24.02.2015 um 21:19 Uhr
-
Zuletzt geändert
08.03.2015 um 13:47 Uhr
-
-
-

Dies ist der zweite Test. -Ich schreibe verschiedene Zeilen Text und teste damit Markdown

-

Ist das jetzt ein neuer Absatz?

-

Und wie kann ich Code-Blöcke wie apt-get install einfügen? Funktioniert das mit 3 oder 4 Backticks?

-

Gehen auch -mehrere -Code-zeilen?

-

Und was ist mit Listen? -- Erster Eintrag -- Zweiter Eintrag -- Erster Untereintrag -- Dritter Eintrag

- -
-
-
-

Ein zweiter Test!

-
-
Autor
homer77
-
Erstellt am
15.02.2015 um 23:18 Uhr
-
Zuletzt geändert
08.03.2015 um 13:46 Uhr
-
-
-

Das ist ein weiter Testartikel

-

Ich muss das abschließen für heute

-

Klick mich

-
-

-
-
-
-
-

Dies ist ein Test

-
-
Autor
homer77
-
Erstellt am
15.02.2015 um 23:16 Uhr
-
Zuletzt geändert
08.03.2015 um 13:47 Uhr
-
-
-

Type your article right here.

-

You may use Markdown to format.

- -
- -
- -
- - - - diff --git a/picoblogger/blog/index.html b/picoblogger/blog/index.html deleted file mode 100644 index 47a512c..0000000 --- a/picoblogger/blog/index.html +++ /dev/null @@ -1,127 +0,0 @@ - - - - Mein Blog - - - - - - - - - - - - - - -
-

Mein Blog

Meine Worte, Meine Meinung ...

-
- -
-
-

Artikel

-
-
-

Das ist der zweite Artikel

-
-
Autor
homer77
-
Erstellt am
24.02.2015 um 21:19 Uhr
-
Zuletzt geändert
08.03.2015 um 13:47 Uhr
-
-
-

Dies ist der zweite Test. -Ich schreibe verschiedene Zeilen Text und teste damit Markdown

-

Ist das jetzt ein neuer Absatz?

-

Und wie kann ich Code-Blöcke wie apt-get install einfügen? Funktioniert das mit 3 oder 4 Backticks?

-

Gehen auch -mehrere -Code-zeilen?

-

Und was ist mit Listen? -- Erster Eintrag -- Zweiter Eintrag -- Erster Untereintrag -- Dritter Eintrag

- -
-
-
-

Ein zweiter Test!

-
-
Autor
homer77
-
Erstellt am
15.02.2015 um 23:18 Uhr
-
Zuletzt geändert
08.03.2015 um 13:46 Uhr
-
-
-

Das ist ein weiter Testartikel

-

Ich muss das abschließen für heute

-

Klick mich

-
-

-
-
-
-
-

Dies ist ein Test

-
-
Autor
homer77
-
Erstellt am
15.02.2015 um 23:16 Uhr
-
Zuletzt geändert
08.03.2015 um 13:47 Uhr
-
-
-

Type your article right here.

-

You may use Markdown to format.

- -
- -
- -
- - - - diff --git a/picoblogger/blog/pb.conf b/picoblogger/blog/pb.conf index 5e6b19c..d2d9270 100644 --- a/picoblogger/blog/pb.conf +++ b/picoblogger/blog/pb.conf @@ -5,6 +5,7 @@ BLOG_SUBTITLE = Meine Worte, Meine Meinung ... # Das ist ein Kommentar zum Test BLOG_LANG = de BLOG_DATE_FORMAT = %d.%m.%Y BLOG_TIME_FORMAT = um %H:%M Uhr +BLOG_CURRENT_ARTICLES = 2 CONTACT_MAIL_ADDRESS = any@mail.address.org CONTACT_SOCIAL_ADDRESS = youraccount@anypod.org diff --git a/picoblogger/main.py b/picoblogger/main.py index 24bfc1d..4cef481 100755 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -62,6 +62,10 @@ print(args) # logged in user user = getpass.getuser() +# current and date +timestamp = time.localtime() + + # set path to blog try: blog_dir = os.path.abspath(os.path.expanduser(vars(args)['blog_dir'])) @@ -132,7 +136,7 @@ try: dateFormat = blogconf['BLOG_DATE_FORMAT'] timeFormat = blogconf['BLOG_TIME_FORMAT'] amountRecent = int(blogconf['RECENT_AMOUNT']) - notToArchive = blogconf['BLOG_CURRENT_ARTICLES'] + nrOfCurrentArticles = int(blogconf['BLOG_CURRENT_ARTICLES']) except: print("Couldn't parse blog's local configuration (%s)."%blogconfpath) @@ -157,6 +161,9 @@ def parse_article(path): header = header.split("HEADER_END")[0] body = markdown.markdown(article.split("HEADER_END")[1]) article_dict = parse_conf(header) + split_path = os.path.split(path) + article_dict['PATH'] = split_path[0] + article_dict['FILENAME'] = split_path[1] article_dict['BODY'] = body article_dict['MODIFIED_DATE'] = time.strftime(dateFormat,time.gmtime(os.stat(path).st_mtime)) article_dict['MODIFIED_TIME'] = time.strftime(timeFormat,time.gmtime(os.stat(path).st_mtime)) @@ -200,11 +207,11 @@ def article_to_html(article_dict): sARTICLE = Template(sARTICLE).safe_substitute(tplSub) return sARTICLE -def join_articles(): - artDir = os.path.join(blog_dir,"articles") +def join_articles(artDir = articleDir): + joined_html = "" articles_dict = {} - for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "\~" in item]: + 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")) @@ -242,10 +249,10 @@ def recent_to_html(article_dict): def recent_articles(amount): - artDir = os.path.join(blog_dir,"articles") + artDir = articleDir joined_html = "" articles_dict = {} - for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "\~" in item]: + 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")) @@ -258,25 +265,82 @@ 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,): +def archive_articles(): + articles = [parse_article(os.path.join(articleDir,item)) for item in os.listdir(articleDir) if not "~" in item] +# print(articles) + cMonth = timestamp.tm_mon + cYear = timestamp.tm_year + # sort articles by date of creation into archive which is structured by subfolders of year and month + for article in articles: + aName = article["FILENAME"] + aPath = os.path.join(article["PATH"], aName) + aDate = time.strptime(article["DATE"],"%m/%d/%y") + aMonth = aDate.tm_mon + aYear = aDate.tm_year - os.replace(draft, article) + # archive only articles older than current month + if (aMonth < cMonth) or (aYear < cYear): + + yearDir = os.path.join(archiveDir,str(aYear)) + monthDir = os.path.join(yearDir,str(aMonth)) + + if not os.path.exists(yearDir): + try: + os.makedirs(monthDir, mode=0o755) + except: + raise + else: + if not os.path.exists(monthDir): + try: + os.mkdir(monthDir, mode=0o755) + except: + raise + replPath = os.path.join(monthDir,aName) + try: + os.replace(aPath,replPath) + print("Archived %s into %s."%(aName,monthDir)) + except: + print("Failed archiving %s."%aName) + raise + +def list_of_months(): + dArchives = {} + years = os.listdir(archiveDir) + for year in years: + yearDir = os.path.join(archiveDir,year) + months = os.listdir(yearDir) + dArchives[year] = [] + for month in months: + monthDir = os.path.join(yearDir,month) + tMonth = time.strptime(month+"/"+year,"%m/%Y") + sMonth = time.strftime("%B",tMonth) + dArchives[year].append(sMonth) + print(dArchives) + return dArchives + + +def list_articles(): + pass + def update_blog(subsection): - # Joins config defined variables into templates + """ Joins config defined variables into templates""" - tplIndex = os.path.join(tplDir,"index.htm") - blogIndex = os.path.join(blog_dir,"index.html") + if subsection == "recent": + tplIndex = os.path.join(tplDir,"index.htm") + blogIndex = os.path.join(blog_dir,"index.html") + elif subsection == "archive": + tplIndex = os.path.join(tplDir,"index.htm") + blogIndex = os.path.join(blog_dir,"archive.html") tpl = Template(open(tplIndex,'r').read()) sNAV = open(os.path.join(tplDir,"nav.htm")).read() sNAV = Template(sNAV).safe_substitute(l10nconf) -# sMAIN = open(os.path.join(tplDir,"main.htm")).read() -# sMAIN = Template(sMAIN).safe_substitute(join_articles()) - sMAIN = join_articles() + if subsection == "recent": + sMAIN = join_articles() + elif subsection == "archive": + sMAIN = list_articles() sASIDE = open(os.path.join(tplDir,"aside.htm")).read() sRECENT = open(os.path.join(tplDir,"recent.htm")).read() @@ -302,7 +366,10 @@ def update_blog(subsection): sRECENT = Template(sRECENT).safe_substitute(pbconf) sFOOTER = Template(sFOOTER).safe_substitute(pbconf) - sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent_articles(amountRecent)}) + if subsection == "recent": + sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent_articles(amountRecent)}) + elif subsection == "archive": + sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":list_of_months()}) sASIDE = Template(sASIDE).safe_substitute({"ASIDE_RECENT":sRECENT, "ASIDE_CONTACT":sCONTACT}) tplSub = { @@ -318,11 +385,6 @@ def update_blog(subsection): print(tmpIndex, file=f) -# def article_to_html(name): -# article = os.path.join(blog_dir,"articles",name + ".txt") -# txt = open(article).read() -# html = markdown.markdown(txt) -# return html ################## @@ -337,6 +399,7 @@ if vars(args)['target'] == 'blog': ## update subsections or whole blog if vars(args)['action'] == 'update': + archive_articles() if vars(args)['subsection'] in ('recent','all'): pass @@ -392,7 +455,7 @@ if vars(args)['target'] == 'draft': if vars(args)['action'] == 'edit': draft = os.path.join(blog_dir,"drafts",vars(args)['name'] + ".txt") - subprocess.call(["emacs", " -nw", draft]) + subprocess.call(["emacs", "-nw", draft]) ## remove draft @@ -420,7 +483,7 @@ if vars(args)['target'] == 'article': article = os.path.join(blog_dir,"articles",vars(args)['name'] + ".txt") tpl = os.path.join(tplDir,"article.tpl") sTpl = open(tpl).read() - subs = {"DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()), + subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()), "AUTHOR" : user } @@ -443,7 +506,7 @@ if vars(args)['target'] == 'article': if vars(args)['action'] == 'edit': draft = os.path.join(blog_dir,"articles",vars(args)['id'] + ".txt") - subprocess.call(["emacs", " -nw", draft]) + subprocess.call(["emacs", "-nw", draft])