Mercurial > repos > vimalkumarvelayudhan > html_export
diff html_export.py @ 0:6423c038695d
First commit
author | Vimalkumar Velayudhan <vimal@biotechcoder.com> |
---|---|
date | Fri, 03 Jul 2015 11:59:29 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/html_export.py Fri Jul 03 11:59:29 2015 +0100 @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import os +import argparse + +parser = argparse.ArgumentParser( + description='Create a HTML output file with link to a sample text file') +parser.add_argument('--html_file', default='html_export.html') +parser.add_argument('--output_path', default=os.getcwd()) +args = parser.parse_args() + +html = """\ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>HTML export</title> + </head> +<body> +<h3>HTML output file with link to sample text file</h3> +<p>Download: {content}</p> +</body> +</html> + +""" + +# create output directory +os.mkdir(args.output_path) + +# create the text file with content +with open(os.path.join(args.output_path, 'paths.txt'), 'w') as f: + paths = os.environ['PATH'].split(':') + f.write('\n'.join(paths)) + +# write html file +with open(args.html_file, 'w') as g: + g.write(html.format(content='<a href="paths.txt">paths.txt</a>'))