import datetime from datetime import datetime import markdown import os from os import path import pathlib import config ENTRY_DIR = 'templates/entry' def gen_arch_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 += '