Last active
July 2, 2021 10:40
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}×tamp={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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I made a quick library out of this: https://github.com/aerupt/whenareyou