Skip to content
Browse files

Add New York Times events; tweak output

  • Loading branch information...
1 parent a9cf676 commit 62343d1c5171c6d0bbff53512cea6348500f216c @mjibson committed
Showing with 27 additions and 4 deletions.
  1. +8 −2 main.py
  2. +2 −0 settings.py.dist
  3. +4 −1 templates/index.html
  4. +13 −1 utils.py
View
10 main.py
@@ -43,17 +43,19 @@ def __str__(self):
return '%f,%f' %(self.lat, self.lng)
class Event:
- def __init__(self, name, address, category, activity):
+ def __init__(self, name, address, category, activity, source):
self.name = name
self.address = address
self.category = category
self.activity = activity
+ self.source = source
class Main(BaseHandler):
def get(self):
pos = Position(settings.TEST_LL[0], settings.TEST_LL[1])
fs = utils.foursquare_trending(pos)
+ nyt = utils.nyt_events(pos)
events = []
@@ -63,8 +65,12 @@ def get(self):
location = e['location'].get('address')
if not location:
location = '%s,%s' %(e['location']['lat'], e['location']['lng'])
+ events.append(Event(e['name'], location, e['categories'][0]['name'], e['hereNow']['count'], 'foursquare'))
- events.append(Event(e['name'], location, e['categories'][0]['name'], e['hereNow']['count']))
+ r = nyt.get_result()
+ j = json.loads(r.content)
+ for e in j['results']:
+ events.append(Event(e['event_name'], e['street_address'], e['category'], 20 if e['times_pick'] else 0, 'new york times'))
self.render('index.html', {
'events': events,
View
2 settings.py.dist
@@ -4,3 +4,5 @@ COOKIE_KEY = ''
FOURSQUARE_CLIENT_ID = ''
FOURSQUARE_CLIENT_SECRET = ''
+
+NYT_API_KEY = ''
View
5 templates/index.html
@@ -4,13 +4,16 @@
{% for e in events %}
<div class="row">
- <div class="span3">
+ <div class="span2">
<h4>{{ e.category }}</h4>
</div>
<div class="span8">
<h2>{{ e.name }}</h2>
{{ e.address }}
</div>
+ <div class="span2">
+ {{ e.source }}
+ </div>
</div>
{% endfor %}
View
14 utils.py
@@ -28,4 +28,16 @@ def foursquare_url(api, **kwargs):
return FOURSQUARE_ENDPOINT + api + '?' + urllib.urlencode(params)
def foursquare_trending(pos):
- return fetch(foursquare_url(FOURSQUARE_TRENDING, ll=pos))
+ return fetch(foursquare_url(FOURSQUARE_TRENDING, ll=pos, limit=5))
+
+NYT_ENDPOINT = 'http://api.nytimes.com/'
+NYT_EVENTS = 'svc/events/v2/listings.json'
+
+def nyt_url(api, **kwargs):
+ params = dict(kwargs)
+ params['api-key'] = settings.NYT_API_KEY
+
+ return NYT_ENDPOINT + api + '?' + urllib.urlencode(params)
+
+def nyt_events(pos):
+ return fetch(nyt_url(NYT_EVENTS, ll=pos, limit=5))

0 comments on commit 62343d1

Please sign in to comment.
Something went wrong with that request. Please try again.