Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions csvtry.py
Original file line number Diff line number Diff line change
@@ -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')
52 changes: 52 additions & 0 deletions nearby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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)
return response.json()

def getNearByAddress(self):
r = self.getNearBy()
for x in r["results"]:
print(x["name"]+" "+x.get("vicinity", ""))