view html_export.py @ 2:ebd2c7b56d10 default tip

Version update (testing)
author Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
date Tue, 24 Nov 2015 11:57:08 +0000
parents 6423c038695d
children
line wrap: on
line source

# -*- 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>'))