diff options
author | dx <aryadevchavali1@gmail.com> | 2020-05-05 22:33:15 +0100 |
---|---|---|
committer | dx <aryadevchavali1@gmail.com> | 2020-05-06 00:54:40 +0100 |
commit | 66fe31e3957d15982421e5e80ff67df795926394 (patch) | |
tree | 00182ef875bdfc161ee100286e0f879ce72a2107 /converter.py | |
parent | 4c9a79a8f44b61d6533a2dbe671ade85eae2db0e (diff) | |
download | mdhtml-66fe31e3957d15982421e5e80ff67df795926394.tar.gz mdhtml-66fe31e3957d15982421e5e80ff67df795926394.tar.bz2 mdhtml-66fe31e3957d15982421e5e80ff67df795926394.zip |
+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.
Diffstat (limited to 'converter.py')
-rw-r--r-- | converter.py | 16 |
1 files changed, 16 insertions, 0 deletions
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) |