def GET(self, cmd): """ The first call get a list of all our past meetups. This list expand as meetups complete, so we should refresh it once a day """ logger.debug('GET /meetup/rsvp/%s' % cmd) decoder = json.JSONDecoder() meetup = MeetupAPI(apikey, lifetime=86400) """ The second meetup instance uses a deprecated API to list the 'attended' counts. This is only available on completed meetups, and is requested per meetup. So it never changes, and we can permanently cache the response. """ m1 = MeetupAPI(apikey, 'http://api.meetup.com/', lifetime=0) finished = False results = [] offset = 0 count = 0 while finished is False: eventlist = meetup.events({'status': 'past', 'group_id': cmd, 'offset': offset, 'page': 20}) try: results.append(decoder.decode(eventlist['text'])['results']) meta = decoder.decode(eventlist['text'])['meta'] count += meta['count'] if count == meta['total_count']: finished = True else: offset += 1 except Exception, e: logger.debug(eventlist) text = decoder.decode(eventlist['text']) # Meetup gives us detailed error conditions in most cases # but I've had these fields not present before if 'problem' not in text: text['problem'] = 'Not specified' if 'details' not in text: text['details'] = 'Not specified' raise web.HTTPError("%d %s" % (eventlist['status'], text['problem']), {}, text['details'])
def GET(self, cmd): logger.debug('GET /meetup/members/%s' % cmd) decoder = json.JSONDecoder() meetup = MeetupAPI(apikey, lifetime=3600) response = None meta = None request = meetup.members({'group_id': cmd, 'page': 20}) try: response = decoder.decode(request['text'])['results'] meta = decoder.decode(request['text'])['meta'] except Exception, e: logger.debug(request) if 'text' in request: text = json.JSONDecoder().decode(request['text']) raise web.HTTPError("%d %s" % (request['status'], text['details']), {}, f) raise web.InternalError(e)
def GET(self, cmd): logger.debug('GET /meetup/events/%s' % cmd) meetup = MeetupAPI(apikey, lifetime=3600) request = meetup.events({'group_id': cmd, 'page': 20}) try: if request['status'] != 200: text = json.JSONDecoder().decode(request['text']) # Meetup gives us detailed error conditions in most cases # but I've had these fields not present before if 'problem' not in text: text['problem'] = 'Not specified' if 'details' not in text: text['details'] = 'Not specified' raise web.HTTPError("%d %s" % (request['status'], text['problem']), {}, text['details']) except KeyError, e: logger.warning('events failed') raise web.InternalError('Bad Object')