Python feedparser.FeedParserDict() Examples
The following are 9
code examples of feedparser.FeedParserDict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
feedparser
, or try the search function
.
Example #1
Source File: twitterbot.py From twitterbot with GNU General Public License v2.0 | 6 votes |
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
Example #2
Source File: fetch_papers.py From arxiv-sanity-preserver with MIT License | 6 votes |
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
Example #3
Source File: update_arxiv.py From xlinkBook with MIT License | 6 votes |
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
Example #4
Source File: arxiv_repo.py From web-miner with MIT License | 6 votes |
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
Example #5
Source File: feed.py From reader with MIT License | 5 votes |
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]
Example #6
Source File: test_feeds.py From CloudBot with GNU General Public License v3.0 | 5 votes |
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()
Example #7
Source File: raw_parser.py From rssant with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #8
Source File: raw_parser.py From rssant with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_feed_title(self, feed: feedparser.FeedParserDict) -> str: return feed.feed.get("title") or \ feed.feed.get("subtitle") or \ feed.feed.get("description")
Example #9
Source File: arxiv_repo.py From web-miner with MIT License | 5 votes |
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