diff --git a/picoblogger/main.py b/picoblogger/main.py index 1fd576d..94847b9 100755 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -22,7 +22,7 @@ parser_blog = subparsers.add_parser('blog', help='add or update blog or its sect ## 'blog' subroutines subparsers_blog = parser_blog.add_subparsers(help="blog subcommands", dest='action') blog_parser_update = subparsers_blog.add_parser('update', help='updates blog to current state') -blog_parser_update.add_argument('subsection', choices=['all','recent','archive','feed'], help='sections of blog you may want to update') +blog_parser_update.add_argument('subsection', choices=['all','recent','archive','tags','feed'], help='sections of blog you may want to update') blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir') # 'draft' command @@ -183,7 +183,7 @@ def parse_article(path): def tags_to_html(tags): tag_list = tags.split(",") html_tags = "" - sTAG = '#${TAG} ' + sTAG = '#${TAG} ' if len(tag_list) > 0 and len(tag_list[0]) > 1: for tag in tag_list: @@ -224,7 +224,7 @@ def join_articles(artDir = articleDir): 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) @@ -339,6 +339,34 @@ def list_articles(folder): return articles_dict +def list_articles_by_tag(): + tags_dict = {} + folder = articleDir + 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"))) + for tag in article['TAGS'].split(","): + tag = tag.strip() + if tag not in tags_dict.keys(): + tags_dict[tag] = list() + tags_dict[tag].append(article) + + months = list_of_months() + for year in months: + for month in months[year]: + monthFolder = os.path.join(archiveDir,str(year),str(month)) + for article in list_articles(monthFolder).values(): + for tag in article['TAGS'].split(","): + tag = tag.strip() + if len(tag) < 2: + continue + if tag not in tags_dict.keys(): + tags_dict[tag] = list() + tags_dict[tag].append(article) + + return tags_dict + + + def list_articles_to_html(folder): artDir = folder joined_html = "" @@ -375,6 +403,7 @@ def list_archive(archived_months): html += "" return html + def templating(dic): sMAIN = "" @@ -482,6 +511,27 @@ def build_archive_articles(): path = os.path.join(article['PATH'],article['FILENAME']) build_article(path) + + +def build_tag(tag,articles): + param={} + param['sRECENT'] = recent_articles(amountRecent) + param['sMAIN'] = list_articles_by_tag() + param['sMAIN_TITLE'] = l10nconf['TAG'] + " #" + tag + htmlTag = os.path.join(htmlDir,tag + ".html") + htmlString = templating(param) +# with open(htmlTag,"w", encoding=l10nconf['BLOG_CHARSET']) as f: +# print(htmlString, file=f) + +def build_tags(): + dic = list_articles_by_tag() + for tag in dic.keys(): + print(tag + " " + str(len(dic[tag]))) + + +def build_feed(): + pass + def update_blog(subsection): """ Joins config defined variables into templates""" @@ -490,9 +540,15 @@ def update_blog(subsection): build_index() build_current_articles() - elif subsection in ("archive","all"): + if subsection in ("archive","all"): build_archive() build_archive_articles() + + if subsection in ("tags"): + build_tags() + + if subsection in ("feed"): + build_feed()