def _parse_json_feed(self, response: FeedResponse) -> RawFeedResult: data = self._load_json(response) if not isinstance(data, dict): raise FeedParserError("JSON feed data should be dict") try: feed: atoma.JSONFeed = atoma.parse_json_feed(data) except atoma.FeedParseError as ex: raise FeedParserError(str(ex)) from ex feed_info = dict( version=feed.version, title=feed.title, url=response.url, home_url=feed.home_page_url, description=feed.description, dt_updated=None, icon_url=feed.icon or feed.favicon, **self._get_json_feed_author(feed.author), ) warnings = [] storys = [] for i, item in enumerate(feed.items or []): story = self._get_json_feed_story(item) if not story: warnings.append(f"story#{i} no id, skip it") continue storys.append(story) if (not storys) and warnings: raise FeedParserError('; '.join(warnings)) result = RawFeedResult(feed_info, storys, warnings=warnings) return result
def _parse_json_feed(self, response: FeedResponse) -> RawFeedResult: data = self._load_json(response) if not isinstance(data, dict): raise FeedParserError("JSON feed data should be dict") try: feed: atoma.JSONFeed = atoma.parse_json_feed(data) except atoma.FeedParseError as ex: raise FeedParserError(str(ex)) from ex feed_info = dict( version=feed.version, title=feed.title, url=response.url, home_url=feed.home_page_url, description=feed.description, dt_updated=None, icon_url=feed.icon or feed.favicon, **self._get_json_feed_author(feed.author), ) warnings = [] storys = [] item: atoma.JSONFeedItem for i, item in enumerate(feed.items or []): ident = item.id_ or item.url or item.title if not ident: warnings.append(f"story#{i} no id, skip it") continue content = item.content_html or item.content_text or item.summary or '' summary = item.summary if item.summary != content else None story = dict( ident=ident, url=item.url, title=item.title or ident, content=content, summary=summary, image_url=item.image or item.banner_image, dt_published=item.date_published, dt_updated=item.date_modified, **self._get_json_feed_author(item.author), ) story = self._normalize_story_content_summary(story) storys.append(story) if (not storys) and warnings: raise FeedParserError('; '.join(warnings)) result = RawFeedResult(feed_info, storys, warnings=warnings) return result