From 8be9cc6eca8e453925b6d023b5cb0a39a86791cc Mon Sep 17 00:00:00 2001 From: Sadeep Nanda <70410776+SadeepNanda@users.noreply.github.com> Date: Sat, 30 Oct 2021 11:26:17 +0530 Subject: [PATCH] Create APIGeolocation.py --- APIGeolocation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 APIGeolocation.py diff --git a/APIGeolocation.py b/APIGeolocation.py new file mode 100644 index 00000000..b1746bd3 --- /dev/null +++ b/APIGeolocation.py @@ -0,0 +1,20 @@ +import urllib.parse , urllib.error , urllib.request +import json +import ssl +s=0 +serviceurl='http://py4e-data.dr-chuck.net/json?' + + +address=input('Enter location :') +url= serviceurl + urllib.parse.urlencode({'address':address,'key' : 42}) +print('Retrieving',url) +data=urllib.request.urlopen(url).read().decode() +print('Retrieved :',len(data),' characters') +try: + info=json.loads(data) +except: + info=None +if not info or 'status' not in info or info['status'] != 'OK': + print('==== Failure To Retrieve ====') + print(data) +print('Place Id ',info["results"][0]["place_id"])