Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active February 24, 2018 07:26
Show Gist options
  • Save cecilialee/8c28512f128991827285ad4404e8aae9 to your computer and use it in GitHub Desktop.
Save cecilialee/8c28512f128991827285ad4404e8aae9 to your computer and use it in GitHub Desktop.
Build x-callback-url in Python. #python #python2
import urllib
import webbrowser
def build_url(app, action, action_parameter_dict):
url = '%s://x-callback-url/%s' % (app, action)
if action_parameter_dict:
par_list = []
for k, v in action_parameter_dict.items():
par_list.append(
k + '=' + urllib.quote(unicode(v).encode('utf8')))
url = url + '?' + '&'.join(par_list)
return url
url = build_url('bear', 'open-note', {'title':'My note title'})
webbrowser.open_new(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment