Skip to content

Instantly share code, notes, and snippets.

@ooola
Forked from zacharyvoase/qr_codify.py
Created March 8, 2013 14:32
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 ooola/5116806 to your computer and use it in GitHub Desktop.
Save ooola/5116806 to your computer and use it in GitHub Desktop.
import sys
import subprocess
import tempfile
import urllib
text = sys.stdin.read()
chart_url_template = ('http://chart.apis.google.com/chart?'
'cht=qr&chs=300x300&chl={data}&chld=H|0')
chart_url = chart_url_template.format(data=urllib.quote(text))
with tempfile.NamedTemporaryFile(mode='w', suffix='.png') as f:
subprocess.check_call(['curl', '-L', chart_url],
stdout=f, stderr=sys.stderr)
subprocess.check_call(['qlmanage', '-p', f.name])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment