From 66fe31e3957d15982421e5e80ff67df795926394 Mon Sep 17 00:00:00 2001 From: dx Date: Tue, 5 May 2020 22:33:15 +0100 Subject: +apply template to content and write to output file This firstly formats the template with certain conditional variables (title and body) and then generates a html file based on the option chosen. The time one was a bit annoying as it required using ctime. --- converter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'converter.py') diff --git a/converter.py b/converter.py index 33b4959..d34774d 100644 --- a/converter.py +++ b/converter.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 from optparse import OptionParser +from os.path import getctime +from time import ctime +from datetime import datetime from re import search, sub """Command line arguments""" @@ -48,3 +51,16 @@ for filename in markdown_files: content_parsed.append(line) markdown_compiled.append({'name': filename, 'content': content_parsed}) +"""Template time""" +for md in markdown_compiled: + header_copy = ''.join(header).replace("%title%", md['name'])\ + .replace("%body%", ''.join(md['content'])) + file_name = "" + if options.output_type.startswith("f"): + file_name = md['name'].replace('.md', '.html') + else: + time = datetime.strptime( + ctime(getctime(md['name'])), "%a %b %d %H:%M:%S %Y") + file_name = str(time).replace(" ", "@") + ".html" + with open(file_name, 'w') as file: + file.write(header_copy) -- cgit v1.2.3-13-gbd6f