Created
November 13, 2022 08:36
-
-
Save AntonOsika/51b39ff2626abef8003a615ccaeb6ffd to your computer and use it in GitHub Desktop.
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
import json | |
import os | |
def writeHTML(j, f): | |
f.write(j["fragment"]["bodyHTML"]) | |
for comment in j["comments"]: | |
f.write(comment["bodyHTML"]) | |
def main(args): | |
# check arguments | |
if len(args) != 3: | |
print("usage: json2html.py <inpur-dir> <output-dir>") | |
print("<input-dir> is the directory containing the JSON files") | |
print("<output-dir> is the directory where the HTML files will be written") | |
return | |
# assign args | |
inputDir = args[1] | |
outputDir = args[2] | |
# check input directory | |
if not os.path.exists(inputDir): | |
print("input directory does not exist") | |
return | |
# check output directory | |
if not os.path.exists(outputDir): | |
print("output directory does not exist") | |
return | |
# get all files in input directory | |
files = os.listdir(inputDir) | |
# iterate over files | |
for file in files: | |
# check if file is a JSON file | |
if file.endswith(".json"): | |
# drop .json extension | |
fileName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment