Skip to content

Instantly share code, notes, and snippets.

@Beyamor
Created January 11, 2014 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Beyamor/8378285 to your computer and use it in GitHub Desktop.
Save Beyamor/8378285 to your computer and use it in GitHub Desktop.
import jsontemplate
import json
import os
import argparse
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
parser = argparse.ArgumentParser()
parser.add_argument("--watch", "-w", action="store_true")
args = parser.parse_args()
def run():
try:
with open("template.html", "r") as f:
template = f.read()
with open("data.json", "r") as f:
data = json.loads(f.read())
result = jsontemplate.expand(template, data)
with open("tom-gibson-resume.html", "w") as f:
f.write(result)
os.system("wkhtmltopdf -B 5 -T 5 -R 5 -L 5 tom-gibson-resume.html tom-gibson-resume.pdf")
except Exception as e:
print(e)
class RecompileHandler(FileSystemEventHandler):
def on_modified(self, event):
index = event.src_path.rfind("/") + 1
name = event.src_path[index:]
if name in ["data.json", "template.html", "style.css"]:
run()
run()
if args.watch:
event_handler = RecompileHandler()
observer = Observer()
observer.schedule(event_handler, ".")
observer.start()
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
observer.stop()
observer.join()
@ColtonPhillips
Copy link

how the hell is args.watch ever true. how is args.watch made to be a thing. if you had a --chince param would you then be able to check args.chince ??

@ColtonPhillips
Copy link

this is ridiculously cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment