Skip to content

Instantly share code, notes, and snippets.

@drdrang
Created January 9, 2014 04:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drdrang/8329584 to your computer and use it in GitHub Desktop.
Save drdrang/8329584 to your computer and use it in GitHub Desktop.
A Pythonista script that gets the address, latitude, and longitude and sends them to Drafts.
import sys
import location, time
import urllib, webbrowser
# Handle argument, if present.
try:
a = sys.argv[1]
except IndexError:
a = ''
# Get the GPS info.
location.start_updates()
time.sleep(5)
loc = location.get_location()
addr = location.reverse_geocode(loc)
location.stop_updates()
# Assemble the output.
spot = '''%s%s
%s, %s %s
%.4f, %.4f''' % \
(a, addr[0]['Street'],
addr[0]['City'], addr[0]['State'], addr[0]['ZIP'],
loc['latitude'], loc['longitude'])
# Send output to Drafts.
webbrowser.open("drafts://x-callback-url/create?text=" + urllib.quote(spot.encode('utf-8')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment