annotate html_export.py @ 1:da900b5a0bda

Add input, test, citations parameters and test-data
author Vimalkumar Velayudhan <vimal@biotechcoder.com>
date Fri, 03 Jul 2015 12:24:49 +0100
parents 6423c038695d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
2 import os
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
3 import argparse
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
4
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
5 parser = argparse.ArgumentParser(
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
6 description='Create a HTML output file with link to a sample text file')
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
7 parser.add_argument('--html_file', default='html_export.html')
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
8 parser.add_argument('--output_path', default=os.getcwd())
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
9 args = parser.parse_args()
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
10
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
11 html = """\
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
12 <!DOCTYPE html>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
13 <html lang="en">
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
14 <head>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
15 <meta charset="utf-8">
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
16 <title>HTML export</title>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
17 </head>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
18 <body>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
19 <h3>HTML output file with link to sample text file</h3>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
20 <p>Download: {content}</p>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
21 </body>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
22 </html>
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
23
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
24 """
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
25
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
26 # create output directory
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
27 os.mkdir(args.output_path)
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
28
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
29 # create the text file with content
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
30 with open(os.path.join(args.output_path, 'paths.txt'), 'w') as f:
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
31 paths = os.environ['PATH'].split(':')
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
32 f.write('\n'.join(paths))
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
33
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
34 # write html file
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
35 with open(args.html_file, 'w') as g:
6423c038695d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
36 g.write(html.format(content='<a href="paths.txt">paths.txt</a>'))