Last active
January 2, 2018 18:26
-
-
Save rhysallister/55e3c6b9fd417a7af35be81b95441ecf to your computer and use it in GitHub Desktop.
outputs plain html given JSON from google docs comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# usage: vertonghen.py filename.json [-- outfile filename.html] | |
import argparse | |
import json | |
parser = argparse.ArgumentParser() | |
parser.add_argument('infile', help="JSON file to be vertonghen'd") | |
parser.add_argument('--outfile', help="HTML file to be created from vertonghen'd JSON data", default="vertonghen.html") | |
args = parser.parse_args() | |
with open(args.infile) as file: | |
with open(args.outfile,'w') as outfile: | |
for item in json.loads(''.join(file.readlines()))['items']: | |
outfile.write('<div><span>{author[displayName]}</span> | <span>{htmlContent}</span></div>'.format(**item)) | |
if len(item["replies"]) > 0: | |
for reply in item["replies"]: | |
outfile.write('<div class="reply"><span>{author[displayName]}</span> | <span>{htmlContent}</span></div>'.format(**reply)) | |
outfile.write('<hr>') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment