def process_feed_item(api_item): """Generate a single item for use in an Atom feed template from an API result.""" # Begin with the fields shared by all feed items. item = { 'id': api_item['id'], 'permalink': api_item['url'], 'published': dateutils.from_iso_format(api_item['published']), 'updated': dateutils.from_iso_format(api_item['updated']), 'actor': process_actor(api_item['actor']), } # Choose which processor to use for this feed item verb_processor = { 'post': process_post, 'share': process_share, 'checkin': process_checkin, }.get(api_item['verb'], process_unknown) item.update(verb_processor(api_item)) return item
def generate_atom(gplus_id, page_id): """Generate an Atom-format feed for the given G+ id.""" # If no page id specified, use the special value 'me' which refers to the # stream for the owner of the OAuth2 token. request = requests.Request('GET', GPLUS_API_ACTIVITIES_ENDPOINT % (page_id or 'me'), params={ 'maxResults': 10, 'userIp': flask.request.remote_addr }) api_response = oauth2.authed_request_for_id(gplus_id, request) result = api_response.json() if page_id: request_url = full_url_for('page_atom', gplus_id=gplus_id, page_id=page_id) else: request_url = full_url_for('user_atom', gplus_id=gplus_id) params = { 'server_url': full_url_for('main'), 'feed_id': page_id or gplus_id, 'request_url': request_url, 'to_atom_date': dateutils.to_atom_format, } items = result.get('items') if not items: params['last_update'] = datetime.datetime.today() body = flask.render_template('atom/empty.xml', **params) else: last_update = max( dateutils.from_iso_format(item['updated']) for item in items) params['last_update'] = last_update params['items'] = process_feed_items(items) params['actor'] = params['items'][0]['actor'] body = flask.render_template('atom/feed.xml', **params) response = flask.make_response(body) response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8' response.date = params['last_update'] return response
def generate_atom(gplus_id, page_id): """Generate an Atom-format feed for the given G+ id.""" # If no page id specified, use the special value 'me' which refers to the # stream for the owner of the OAuth2 token. request = requests.Request('GET', GPLUS_API_ACTIVITIES_ENDPOINT % (page_id or 'me'), params={'maxResults': 10, 'userIp': flask.request.remote_addr}) api_response = oauth2.authed_request_for_id(gplus_id, request) result = api_response.json() if page_id: request_url = full_url_for('page_atom', gplus_id=gplus_id, page_id=page_id) else: request_url = full_url_for('user_atom', gplus_id=gplus_id) params = { 'server_url': full_url_for('main'), 'feed_id': page_id or gplus_id, 'request_url': request_url, 'to_atom_date': dateutils.to_atom_format, } items = result.get('items') if not items: params['last_update'] = datetime.datetime.today() body = flask.render_template('atom/empty.xml', **params) else: last_update = max(dateutils.from_iso_format(item['updated']) for item in items) params['last_update'] = last_update params['items'] = process_feed_items(items) params['actor'] = params['items'][0]['actor'] body = flask.render_template('atom/feed.xml', **params) response = flask.make_response(body) response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8' response.date = params['last_update'] return response