Instantly share code, notes, and snippets.

What would you like to do?
Create static HTML from a Gist ID. See for more info.
#!/usr/bin/env python3
import urllib.request
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtScript import QScriptEngine, QScriptValue
def doc_write(context, eng):
if context.argumentCount() != 0:
na = context.argumentCount()
args = list()
for i in range(na):
args.append( str(context.argument(i).toVariant()))
temp = ' '.join(args)
# if not 'embed.css' in temp: broke when running the script on itself!
if not temp.startswith('<link rel="stylesheet"'):
temp = temp.replace("\n", '')
return QScriptValue('')
def main(args):
gist_id = None
if len(sys.argv) > 1:
gist_id = args[0]
print("No Gist ID given!")
url = "{gist_id}.js".format(gist_id=gist_id)
app = QtCore.QCoreApplication(args)
qse = QScriptEngine()
dw = qse.newFunction(doc_write)
qse.globalObject().setProperty('doc_write', dw)
fh = urllib.request.urlopen(url)
gist_script ='utf-8')
gist_script = gist_script.replace('document.write', 'doc_write')
res = qse.evaluate(gist_script)
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment