Skip to content

Instantly share code, notes, and snippets.

@zillwc
Created July 18, 2017 06:12
Show Gist options
  • Select an option

  • Save zillwc/3d911fdd6569f021950f9067c5cdf819 to your computer and use it in GitHub Desktop.

Select an option

Save zillwc/3d911fdd6569f021950f9067c5cdf819 to your computer and use it in GitHub Desktop.
Generates a QR code image based on highlighted words (intended to be used with Apple workflow as a service)
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