Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: dvanoni/TheHack
base: 66ceee6952
...
head fork: dvanoni/TheHack
compare: 52189aaa3e
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 13, 2011
Lynn Nguyen incorporate google places 8858fe0
Lynn Nguyen slightly more detailed comment 52189aa
Showing with 41 additions and 6 deletions.
  1. +41 −6 backend/server.py
47 backend/server.py
View
@@ -10,11 +10,17 @@
ECHONEST_KEY = 'YBBLFZVQBRPQF1VKS'
ECHONEST_API = 'http://developer.echonest.com/api/v4/song/search'
+PLACES_KEY = 'AIzaSyCvfId0lM9v_F2igUi4AIRbFJHr8IlMFAY'
+PLACES_API = 'https://maps.googleapis.com/maps/api/place/search/json'
+
BACK_END = bottle.Bottle()
class EchonestMagicError(Exception):
pass
+class SearchError(Exception):
+ pass
+
@BACK_END.route('/echonest_magic', method='GET')
def echonest_magic():
# TODO: grab phone data
@@ -25,14 +31,14 @@ def echonest_magic():
gps_location = request.GET.get('gps_location', '').strip()
args = {\
- 'api_key' : ECHONEST_KEY,\
+ 'api_key' : ECHONEST_KEY,\
- # limit songs to those found in 7digital catalog
- 'bucket' : 'id:7digital-US',\
- 'limit' : 'true',\
+ # limit songs to those found in 7digital catalog
+ 'bucket' : 'id:7digital-US',\
+ 'limit' : 'true',\
- # TODO: our own magic parameters
- 'artist' : 'Calvin Harris',\
+ # TODO: our own magic parameters
+ 'artist' : 'Calvin Harris',\
}
url = ECHONEST_API + '?' + urllib.urlencode(args) + '&bucket=tracks'
@@ -47,3 +53,32 @@ def echonest_magic():
songs = result['response']['songs']
return template('song_dump', songs=songs)
+
+@BACK_END.route('/places_magic', method='GET')
+def places_magic():
+ latitude = request.GET.get('latitude', '').strip()
+ longitude = request.GET.get('longitude', '').strip()
+
+ #TODO: the moma
+ latitude = '40.77905519999999'
+ longitude = '-73.96283459999999'
+
+ args = {\
+ 'location' : '%s,%s' % (latitude, longitude),\
+ 'radius' : 10,\
+ 'sensor' : 'true',\
+ 'key' : PLACES_KEY
+ }
+
+ url = PLACES_API + '?' + urllib.urlencode(args)
+ result = json.load(urllib.urlopen(url))
+
+
+ if 'Error' in result:
+ # An error occurred; raise an exception
+ raise SearchError, result['Error']
+
+ # grab the categories of the first place
+ place = result['results'][0]
+
+ return place['types']

No commit comments for this range

Something went wrong with that request. Please try again.