Skip to content
Permalink
a5256e7a02
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
61 lines (40 sloc) 1.99 KB
import requests
def GetLocation():
"""Function that accesses the url below, and while utilizing my API key, it retrieves
your IP from your device plus the country, city latitude and longitude of said device"""
###API obtained from api.ipstack.com
url = 'http://api.ipstack.com/80.6.96.49?access_key=0aacafdcf8c3bb1e767b09c8f3bd60b0'
response = requests.get(url)
data = response.json()
ip = data['ip']
country = data['country_name']
city = data['city']
lat = data['latitude']
long = data['longitude']
return "Your device's IP is: {0} \n" \
"You're located in {1}, {2} \n" \
"Latitude: {3} \n" \
"Longitude: {4}".format(ip, city, country, lat, long)
def SearchPlaces(radius, type):
"""Function that takes an integer and string as input, where the integer
is the radius and the string is the type of place to be searched, and retrieves the places and ratings under that radius"""
placesList = []
ratingList = []
urlLocation = 'http://api.ipstack.com/80.6.96.49?access_key=0aacafdcf8c3bb1e767b09c8f3bd60b0'
responseLocation = requests.get(urlLocation)
dataLocation = responseLocation.json()
lat = dataLocation['latitude']
long = dataLocation['longitude']
###API from googleapis.com
api = 'AIzaSyB5VJi-U8jTUAIuKnFX9ua-tX-mzV8Heq4'
urlPlaces = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={0},{1}&radius={2}&type={3}&key={4}'.format(lat, long, radius, type, api)
responsePlaces = requests.get(urlPlaces)
dataPlaces = responsePlaces.json()
places = dataPlaces['results']
for results in range(len(places)):
placesList.append(places[results]['name'])
ratingList.append(places[results]['rating'])
###Got the str.join() from a thread in StackOverflow, but I can't remember which
result1 = "\n".join("{0} : {1}".format(x, y) for x, y in zip(placesList, ratingList))
return result1
#print(SearchPlacesnt(1500), str("restaurant")))(i