-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathautogen.py
More file actions
executable file
·28 lines (22 loc) · 872 Bytes
/
autogen.py
File metadata and controls
executable file
·28 lines (22 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
import argparse
import json
import os
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument('name', help='Base name of html file to generate. name.md must exist.')
args = parser.parse_args()
name = args.name
with open(name + '.md', 'r') as md_file, \
open(name + '.html', 'w') as html_file, \
open('header', 'r') as header_file, \
open('footer', 'r') as footer_file:
data = {"text": md_file.read(), "mode": "gfm"}
p = subprocess.Popen(['curl', '-s', '--data-binary', '@-', 'https://api.github.com/markdown'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate(json.dumps(data))
if p.returncode != 0:
print 'Error calling curl: ' + err, sys.stderr
html_file.write(header_file.read())
html_file.write(out)
html_file.write(footer_file.read())