Created
December 23, 2011 04:59
-
-
Save jl2/1513192 to your computer and use it in GitHub Desktop.
Create static HTML from a Gist ID. See http://jlarocco.com/2011/12/22/static-gist-creator/ for more info.
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 | |
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", '') | |
print(temp) | |
return QScriptValue('') | |
def main(args): | |
gist_id = None | |
if len(sys.argv) > 1: | |
gist_id = args[0] | |
else: | |
print("No Gist ID given!") | |
exit(0) | |
url = "https://gist.github.com/{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 = fh.read().decode('utf-8') | |
gist_script = gist_script.replace('document.write', 'doc_write') | |
res = qse.evaluate(gist_script) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment