From 439a94c0ea32b2171ff0f0976f40f40276922989 Mon Sep 17 00:00:00 2001 From: vaishnaviajmera22 Date: Fri, 1 Jun 2018 12:16:09 +0530 Subject: [PATCH 1/3] The Function --- nearby.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 nearby.py diff --git a/nearby.py b/nearby.py new file mode 100644 index 0000000..3ec026c --- /dev/null +++ b/nearby.py @@ -0,0 +1,56 @@ +import requests + +#now 2 tasks + +# 1 change the whole program to Object oriented style +# e.g. a = GoogleMapPlaces("Chittorgarh", "1500", "Pizza", "") should create object +# a.getNearByAddress() should give result + + +# 2 Get your own API Key from google cloud console +# open terminal arey baba yaha pr +class GoogleMapPlaces: + API_KEY = "AIzaSyDZMs9AfgNI0fcvENgUK6pM6lS3wbptcbE" + + def __init__(self, address, radius, type, keyword): + self.address = address + self.radius = radius + self.type = type + self.keyword = keyword + + + def addressToCoordinates(self): + url = "https://maps.googleapis.com/maps/api/geocode/json" + + querystring = {"address":self.address,"key":self.API_KEY} + + + response = requests.request("GET", url, params=querystring) + + # check if response is 'ok' then return result + if response.json()["status"]=="OK": + return response.json()["results"][0]["geometry"]["location"] + else: + print(response.text) + return { "error": "Not found"} + + def getNearBy(self): + location = self.addressToCoordinates() + x= location["lat"] + y= location["lng"] + loc=str(x)+","+str(y) + url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" + + querystring = {"location":loc,"radius":self.radius,"type":self.type,"keyword":self.keyword,"key":self.API_KEY} + + response = requests.request("GET", url, params=querystring) + print(response.text) + return response.json() + + def getNearByAddress(self): + r = self.getNearBy() + for x in r["results"]: + print(x["name"]+" "+x.get("vicinity", "")) + +a = GoogleMapPlaces("Chittorgarh", "1500", "restaurant", "pizza") +a.getNearByAddress() From 47d19eb2af40e6cecfb821ca7ba8db6c69aae27c Mon Sep 17 00:00:00 2001 From: vaishnaviajmera22 Date: Sat, 2 Jun 2018 17:33:38 +0530 Subject: [PATCH 2/3] Google Maps Nearby Implementation --- nearby.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nearby.py b/nearby.py index 3ec026c..79ece8a 100644 --- a/nearby.py +++ b/nearby.py @@ -44,13 +44,9 @@ def getNearBy(self): querystring = {"location":loc,"radius":self.radius,"type":self.type,"keyword":self.keyword,"key":self.API_KEY} response = requests.request("GET", url, params=querystring) - print(response.text) return response.json() def getNearByAddress(self): r = self.getNearBy() for x in r["results"]: print(x["name"]+" "+x.get("vicinity", "")) - -a = GoogleMapPlaces("Chittorgarh", "1500", "restaurant", "pizza") -a.getNearByAddress() From 16bb090a1985fd803c1b34d210d5e47be52134cc Mon Sep 17 00:00:00 2001 From: vaishnaviajmera22 Date: Mon, 4 Jun 2018 11:54:19 +0530 Subject: [PATCH 3/3] CSV Practice --- csvtry.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 csvtry.py diff --git a/csvtry.py b/csvtry.py new file mode 100644 index 0000000..b7ce4bd --- /dev/null +++ b/csvtry.py @@ -0,0 +1,53 @@ +import csv + +fields = ['Name', 'Branch', 'Year', 'CGPA'] + +# data rows of csv file +rows = [ ['Nikhil', 'COE', '2', '9.0'], + ['Sanchit', 'COE', '2', '9.1'], + ['Aditya', 'IT', '2', '9.3'], + ['Sagar', 'SE', '1', '9.5'], + ['Prateek', 'MCE', '3', '7.8'], + ['Sahil', 'EP', '2', '9.1']] + +# name of csv file +filename = "university_records.csv" + +# writing to csv file +with open(filename, 'w') as csvfile: + # creating a csv writer object + csvwriter = csv.writer(csvfile) + + # writing the fields + csvwriter.writerow(fields) + + # writing the data rows + csvwriter.writerows(rows) + + +fields = [] +rows = [] + +# reading csv file +with open(filename, 'r') as csvfile: + # creating a csv reader object + csvreader = csv.reader(csvfile) + + # extracting field names through first row + fields = next(csvreader) + # extracting each data row one by one + for row in csvreader: + rows.append(row) + + # get total number of rows + print("Total no. of rows: %d"%(csvreader.line_num)) + +# printing the field names +print('Field names are:\n' + ' '.join(field for field in fields)) + + +for row in rows[:5]: + # parsing each column of a row + for col in row: + print("%10s"%col) + print('\n')