Skip to content

Instantly share code, notes, and snippets.

@willcharlton
Last active July 2, 2021 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save willcharlton/b055885e249a902402fc to your computer and use it in GitHub Desktop.
Save willcharlton/b055885e249a902402fc to your computer and use it in GitHub Desktop.
Python (3) snippet to generate google maps url and timezone for a given address.
#!/usr/bin/env python3
"""
So far only tested on python3 interpreter.
Given an address, this script outputs a google maps url to the address.
"""
import requests, sys, time
from urllib.parse import quote_plus
def main():
print("""Enter address.
Example:
Exosite
275 Market St
Suite 535
Minneapolis, MN 55405
<then hit CNTL-D>
When done, hit CNTL-D.
""")
address = ''
while True:
line = sys.stdin.readline() # readline will return "" on EOF
if line != "":
address += line
else:
break
linkurl = 'https://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false'.format(quote_plus(address))
linkblob = requests.get(linkurl).json()
latlong = linkblob['results'][0]['geometry']['location']
print('Link to map of address: https://www.google.com/maps?q={0},{1}'.format(latlong['lat'], latlong['lng']))
tzurl = 'https://maps.googleapis.com/maps/api/timezone/json?location={0},{1}&timestamp={2}'.format(latlong['lat'], latlong['lng'], int(time.time()))
tzblob = requests.get(tzurl).json()
print("Timezone of address {0}".format(tzblob['timeZoneId']))
if __name__ == '__main__':
main()
@sils
Copy link

sils commented Feb 21, 2017

Hey, I made a quick library out of this: https://github.com/aerupt/whenareyou

@willcharlton
Copy link
Author

@sils - Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment