import locale import os import pathlib from datetime import datetime from os import path import config import markdown ENTRY_DIR = "templates/entry" LANGUAGE = config.LANGUAGE LOCAL = "de_DE.UTF-8" if LANGUAGE == "de-de" else "en_US.UTF-8" locale.setlocale(locale.LC_TIME, LOCAL) standalone_str = "Artikel" if LANGUAGE == "de-de" else "standalone" def gen_arch_string(): """ Creates and returns a archive string of every file in ENTRY_DIR. Returns: string: html-formatted archive-string """ path_ex = ENTRY_DIR if path.exists(path_ex): name_list = os.listdir(path_ex) full_list = [os.path.join(path_ex, i) for i in name_list] contents = sorted(full_list, key=os.path.getctime) content_string = "" last_month = "" for file in reversed(contents): curr_date = datetime.fromtimestamp(os.path.getctime(file)).strftime("%Y-%m-%d") curr_month = datetime.fromtimestamp(os.path.getctime(file)).strftime("%B %Y") if curr_month != last_month: if last_month != "": content_string += "\n" content_string += "