Skip to content

Instantly share code, notes, and snippets.

@ekarulf
Last active December 14, 2015 14:38
Show Gist options
  • Save ekarulf/5101549 to your computer and use it in GitHub Desktop.
Save ekarulf/5101549 to your computer and use it in GitHub Desktop.
Iterating on a QR service Source: http://zacharyvoase.com/2013/03/06/qr-codify/ Install into ~/Library/Services using Automator
import sys
import subprocess
import tempfile
import urllib
with tempfile.NamedTemporaryFile(mode='w', suffix='.png') as f:
try:
subprocess.check_call('qrencode -V'.split())
except OSError:
print "Rendering QR Code using Google Charts API"
text = sys.stdin.read()
chart_url_template = ('https://chart.googleapis.com/chart?'
'cht=qr&chs=300x300&chl={data}&chld=H|0')
chart_url = chart_url_template.format(data=urllib.quote(text))
subprocess.check_call(['curl', '-L', chart_url],
stdout=f, stderr=sys.stderr)
else:
print "Rendering QR Code using qrencode"
subprocess.check_call('qrencode -o - -l L -s 15 --'.split(),
stdin=sys.stdin, 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