當前位置: 首頁>>代碼示例>>Python>>正文


Python feedparser.FeedParserDict方法代碼示例

本文整理匯總了Python中feedparser.FeedParserDict方法的典型用法代碼示例。如果您正苦於以下問題:Python feedparser.FeedParserDict方法的具體用法?Python feedparser.FeedParserDict怎麽用?Python feedparser.FeedParserDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在feedparser的用法示例。


在下文中一共展示了feedparser.FeedParserDict方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: compose_message

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def compose_message(item: feedparser.FeedParserDict) -> str:
    """Compose a tweet from an RSS item (title, link, description)
    and return final tweet message.

    Parameters
    ----------
    item: feedparser.FeedParserDict
        An RSS item.

    Returns
    -------
    str
        Returns a message suited for a Twitter status update.
    """
    title, link, _ = item["title"], item["link"], item["description"]
    message = shorten_text(title, maxlength=250) + " " + link
    return message 
開發者ID:peterdalle,項目名稱:twitterbot,代碼行數:19,代碼來源:twitterbot.py

示例2: encode_feedparser_dict

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def encode_feedparser_dict(d):
  """ 
  helper function to get rid of feedparser bs with a deep copy. 
  I hate when libs wrap simple things in their own classes.
  """
  if isinstance(d, feedparser.FeedParserDict) or isinstance(d, dict):
    j = {}
    for k in d.keys():
      j[k] = encode_feedparser_dict(d[k])
    return j
  elif isinstance(d, list):
    l = []
    for k in d:
      l.append(encode_feedparser_dict(k))
    return l
  else:
    return d 
開發者ID:karpathy,項目名稱:arxiv-sanity-preserver,代碼行數:19,代碼來源:fetch_papers.py

示例3: encode_feedparser_dict

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def encode_feedparser_dict(self, d):
        """   
        helper function to get rid of feedparser bs with a deep copy. 
        I hate when libs wrap simple things in their own classes.
        """
        if isinstance(d, feedparser.FeedParserDict) or isinstance(d, dict):
          j = {} 
          for k in d.keys():
            j[k] = self.encode_feedparser_dict(d[k])
          return j
        elif isinstance(d, list):
          l = []
          for k in d:
            l.append(self.encode_feedparser_dict(k))
          return l
        else:
          return d 
開發者ID:wowdd1,項目名稱:xlinkBook,代碼行數:19,代碼來源:update_arxiv.py

示例4: run_query

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def run_query(self, search_query, start=0, max_results=10):
        """Queries url and returns a parsed response

        Args:
            search_query (string): The terms we are looking for
            start (int, optional): Defaults to 0. Start at results page
            max_results (int, optional):
                Defaults to 10. How many results shall be retrieved

        Returns:
            FeedParserDict: A parsed dictionary with the information
        """

        query = f"search_query={search_query}&sortBy=lastUpdatedDate&start={start}&max_results={max_results}"  # pylint: disable=C0301
        r = requests.get(self.base_url + query)
        parsed_response = feedparser.parse(r.text)

        return parsed_response 
開發者ID:Keep-Current,項目名稱:web-miner,代碼行數:20,代碼來源:arxiv_repo.py

示例5: _feed

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def _feed(url=URL):  # type: (str) -> feedparser.FeedParserDict
    """Cache contents of the feed, so it's only read once"""
    if url not in _CACHED_FEEDS:
        _CACHED_FEEDS[url] = feedparser.parse(url)
    return _CACHED_FEEDS[url] 
開發者ID:realpython,項目名稱:reader,代碼行數:7,代碼來源:feed.py

示例6: test_feeds

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def test_feeds(mock_feedparse, patch_try_shorten):
    from plugins import feeds

    mock_feedparse.return_value = FeedParserDict(
        entries=[],
    )
    assert feeds.rss('xkcd') == "Feed not found."

    mock_feedparse.assert_called_with('http://xkcd.com/rss.xml')

    mock_feedparse.reset_mock()

    mock_feedparse.return_value = FeedParserDict(
        entries=[FeedParserDict(title='foo1', link='http://example.com')],
        feed=FeedParserDict(title='test'),
    )

    with_title = "\x02test\x02: foo1 (http://example.com)"

    assert feeds.rss('http://rss.example.com/feed.xml') == with_title

    mock_feedparse.assert_called_with('http://rss.example.com/feed.xml')

    mock_feedparse.reset_mock()

    mock_feedparse.return_value = FeedParserDict(
        entries=[FeedParserDict(title='foo1', link='http://example.com')],
        feed=FeedParserDict(),
    )

    without_title = "foo1 (http://example.com)"

    assert feeds.rss('http://rss.example.com/feed.xml') == without_title

    mock_feedparse.assert_called_with('http://rss.example.com/feed.xml')

    mock_feedparse.reset_mock() 
開發者ID:TotallyNotRobots,項目名稱:CloudBot,代碼行數:39,代碼來源:test_feeds.py

示例7: _get_feed_home_url

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def _get_feed_home_url(self, feed: feedparser.FeedParserDict) -> str:
        link = feed.feed.get("link") or ''
        if not link.startswith('http') and not link.startswith('/'):
            # 有些link屬性不是URL,用author_detail的href代替
            # 例如:'http://www.cnblogs.com/grenet/'
            author_detail = feed.feed.get('author_detail')
            if author_detail:
                link = author_detail.get('href')
        return link 
開發者ID:anyant,項目名稱:rssant,代碼行數:11,代碼來源:raw_parser.py

示例8: _get_feed_title

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def _get_feed_title(self, feed: feedparser.FeedParserDict) -> str:
        return feed.feed.get("title") or \
            feed.feed.get("subtitle") or \
            feed.feed.get("description") 
開發者ID:anyant,項目名稱:rssant,代碼行數:6,代碼來源:raw_parser.py

示例9: list

# 需要導入模塊: import feedparser [as 別名]
# 或者: from feedparser import FeedParserDict [as 別名]
def list(self, filters=None):
        """Apply filters on entries and return a filtered list
            filters (dict, optional): Defaults to None. Parameters to filter entries

        Returns:
            list: List of arxiv document objects
        """

        if not filters:
            return self._entries

        self._entries = self.fetch_papers()

        result = []
        result.extend(self._entries)

        for key, value in filters.items():
            result = [e for e in result if self._check(e, key, value)]

        return [ad.ArxivDocument.from_dict(r) for r in result]

    # @classmethod
    # def encode_feedparser_dict(cls, fp_dict):
    #     """
    #     recursive function to convert the internal feedparse object to a simple dict
    #     """
    #     if isinstance(fp_dict, feedparser.FeedParserDict) or isinstance(fp_dict, dict):
    #         ret_dict = {}
    #         for key in fp_dict.keys():
    #             ret_dict[key] = self.encode_feedparser_dict(fp_dict[key])
    #         return ret_dict
    #     elif isinstance(fp_dict, list):
    #         dict_list = []
    #         for key in fp_dict:
    #             dict_list.append(self.encode_feedparser_dict(key))
    #         return dict_list
    #     else:
    #         return fp_dict 
開發者ID:Keep-Current,項目名稱:web-miner,代碼行數:40,代碼來源:arxiv_repo.py


注:本文中的feedparser.FeedParserDict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。