def _refresh_stream(self, mirror_service, token=None): if not token: token = self._get_auth_token() if token: fa = FeedlyAPI(FEEDLY_USER, FEEDLY_SECRET) profile = fa.getProfile(token) if 'errorCode' in profile: refresh_token = self._get_refresh_token() resp = fa.refreshToken(refresh_token) if 'access_token' in resp: token = resp['access_token'] self._set_auth_token(token) profile = fa.getProfile(None) userId = profile['id'] if hasattr(self,'userid'): self._subscribeTimelineEvent(mirror_service, self.userid) existing_cards = self._clearTimeline(mirror_service) batch = BatchHttpRequest() if not existing_cards[CARD_COVER_TITLE]: cardCover = self._create_bundle_cover(1) batch.add( mirror_service.timeline().insert(body=cardCover), request_id=str(userId)+'-cover' ) else: batch.add( mirror_service.timeline().update(id=existing_cards[CARD_COVER_TITLE]['id'], body=existing_cards[CARD_COVER_TITLE]), request_id=str(userId)+'-cover' ) if not existing_cards[CARD_REFRESH_TITLE]: cardRefresh = self._create_refresh_card(self._get_refresh_id(userId), 1) batch.add( mirror_service.timeline().insert(body=cardRefresh), request_id=str(userId)+'-refresh' ) else: self._del_refresh_card(existing_cards[CARD_REFRESH_TITLE]['sourceItemId']) id = self._get_refresh_id(userId) self._set_refresh_card(id) existing_cards[CARD_REFRESH_TITLE]['sourceItemId'] = id batch.add( mirror_service.timeline().update(id=existing_cards[CARD_REFRESH_TITLE]['id'], body=existing_cards[CARD_REFRESH_TITLE]), request_id=str(userId)+'-refresh' ) feed_content = fa.getStreamContentUser(token, userId, count=5, unreadOnly='true') logging.debug(feed_content) if feed_content['items']: markEntryIds = [] for item in feed_content['items']: logging.debug(item['title']) image = None if 'thumbnail' in item: image = item['thumbnail'][0]['url'] elif 'visual' in item and 'url' in item['visual']: image = item['visual']['url'] elif 'summary' in item and 'content' in item['summary'] and 'src=' in item['summary']['content']: start_loc = item['summary']['content'].find('src="') end_loc = item['summary']['content'].find('"', start_loc+5) if start_loc != -1 and end_loc != -1: image = item['summary']['content'][start_loc+5:end_loc] markEntryIds.append(item['id']) source_id = self._get_source_id(userId,item['id']) body = self._create_card(source_id, item['title'], item['origin']['title'], image, item['alternate'][0]['href'], 1) batch.add( mirror_service.timeline().insert(body=body), request_id=item['id'] ) batch.execute(httplib2.Http()) fa.markAsRead(token, markEntryIds)