def gather_choices(self) -> Dict[str, Feed]: feeds = dict() for feed in self.feed_list: # For each feed in our temporary ListStore name = feed[0] feeds[name] = Feed(name=name, uri=feed[1]) return feeds
def test_run_write(self): spy = mock.Mock(wraps=Feed()) cli = Cli(spy) cli.run(self.josh_hello_cmd) spy.post_message.assert_called_once_with(username="******", message="Hello!") spy.get_messages_of.assert_not_called()
def test_download_feed_invalid_date(self): feed_req_obj = Feed(FeedType.ITEM.value, FeedScope.BOOTSTRAP.value, '220', 'EBAY_US', 'Bearer v^1 ...', download_location='tests/sdk/test-data/', feed_date='2019-02-01') get_response = feed_req_obj.get() self.assertEqual(get_response.status_code, FAILURE_CODE) self.assertIsNotNone(get_response.message) self.assertIsNotNone(get_response.file_path, 'file_path is None in the response')
def main() -> None: url = "https://www.example.com/blog/" feed_kwargs = {"url": url, "name": "Fionn", "email": "*****@*****.**", "generator": "generator-name", "generator_version": "0.1.2.3", "logo": "https://www.example.com/logo.png", "icon": "https://www.example.com/icon.png", "description": "Blog blog", "language": "en" } feed = Feed(**feed_kwargs) feed.add_from_blog(url) # Print the Atom feed to stdout print(feed.atom().decode()) # Print the RSS feed to stdout print(feed.rss().decode()) # Produce feed.xml, feed.atom feed.atom_file() feed.rss_file()
def setUp(self): feed = Feed('data/2014-04-05_16-54.atom') ''' <entry> <id>feedzilla.com:368827171</id> <title type="html">'Pulse Signal' Detected in Search for Missing Jet (TIME Blogs)</title> <summary type="html"> A Chinese search team said it detected signals that could lead to the Malaysia Airlines flight's black box, but time is running out (lots of awful HTML share links) </summary> <published>2014-04-05T14:20:00+01:00</published> <updated>2014-04-05T14:20:00+01:00</updated> <author> <name>Sam Frizell</name> </author> <link rel="alternate" href="http://news.feedzilla.com/en_us/stories/world-news/368827171 ?count=100&client_source=api&format=atom" /> <rights type="text"></rights> <source> <title type="text">TIME Blogs</title><link rel="self" href="http://feeds.feedburner.com/timeblogs/middle_east?format=xml" /> </source> </entry> ''' self.article1 = feed.articles[368827171] self.article1.extract(1)
def test_equality(self): name_1 = 'name1' name_2 = 'name2' uri_1 = 'uri1' uri_2 = 'uri2' self.assertNotEqual(name_1, name_2) self.assertNotEqual(uri_1, uri_2) same_name_feed = Feed(name_1, uri_1) same_name_feed_2 = Feed(same_name_feed.name, uri_2) self.assertEqual(same_name_feed, same_name_feed_2) diff_name_feed = Feed(name_2, uri_1) self.assertNotEqual(same_name_feed, diff_name_feed) self.assertNotEqual(same_name_feed, None)
def write(self, comic_link): comics = read() if comic_link not in comics: comics[comic_link] = Feed(comic_link) f = open(_pickle_jar, 'w') cPickle.dump(comics, f) f.close()
def parse(self): """ 进行解析 Return: Feed: 封装好的Feed对象 """ try: data = feedparser.parse(self._resource) feed = Feed() # 设置基本属性 feed.title = data.feed.title feed.updated = data.feed.updated feed.version = data.version # 遍历item for item in data.entries: title = item.title published = item.published link = item.link feed.add_item(title, published, link) except Exception as e: logging.exception(e) raise exceptions.ParserException() else: return feed
class LiveFeedWidget(LiveWidget): """ A live streaming feed widget """ params = { 'url': 'The feed URL', 'topic': 'A topic or list of topics to subscribe to', 'feed': 'A moksha Feed object', 'd': 'The widget data', 'limit': 'The number of entries to display', } template = '${feed(id=id, url=url, limit=limit)}' onmessage = """ $.each(json, function() { $("#${id} ul li:last").remove(); $("<li/>").html( $("<a/>") .attr("href", this.link) .text(this.title)) .prependTo($("#${id} ul")); }); """ feed = Feed() topic = None limit = 10 def update_params(self, d): if not d.get('topic'): d['topic'] = 'feed.%s' % d.get('url', self.url) super(LiveFeedWidget, self).update_params(d) d.d = d
def test_link_message_to_user(self): feed = Feed() username = "******" message = "Hello!" feed.post_message(username, message) actual_messages = feed.get_messages_of(username) self.assertEqual([message], actual_messages)
class LiveFeedWidget(LiveWidget): """ A live streaming feed widget """ url = twc.Param("The feed URL") topic = twc.Param("A topic or list of topics to subscribe to") feed = twc.Param("A moksha Feed object") d = twc.Param("The widget data") limit = twc.Param("The number of entries to display") template = "mako:mako:moksha.feeds.widgets.templates.live" onmessage = """ $.each(json, function() { $("#${id} ul li:last").remove(); $("<li/>").html( $("<a/>") .attr("href", this.link) .text(this.title)) .prependTo($("#${id} ul")); }); """ feed = Feed() topic = None limit = 10 def prepare(self): if not getattr(self, 'topic', None): self.topic = 'feed.%s' % d.get('url', self.url) super(LiveFeedWidget, self).prepare() self.d = self # Wha?
def test_from_feed(self): # # Commented out because search doesn't always have 10 things to return # q="flight" # url="http://api.feedzilla.com/v1/categories/27/articles/search.atom?q="+q+"&count=10" url = "http://api.feedzilla.com/v1/categories/16/articles.atom?count=10" feed = Feed(url) self.assertEqual(len(feed.articles),10)
def generate_feed(loading=False): feed_objects = [] entire_feed = [] rsslinks = None remove_duplicate_lines() with open('links.txt', 'r') as f: rsslinks = f.read().splitlines() if loading: loading_sequence = "Loading feed [0/26]" print(loading_sequence, end="") try: for i in range(len(rsslinks)): link = rsslinks[i] if loading: loading_sequence = ('\b'*len(loading_sequence)) + \ f"Loading feed [{i+1}/{len(rsslinks)}]" print(loading_sequence, end="", flush=True) feed_objects.append(Feed(link)) print("") for feed_object in feed_objects: entire_feed += feed_object.updated_feed except InvalidRSSError: print( "One of the RSS links either aren't up to standard or isn't valid." ) return entire_feed
def country_articles(country=None): from feed import Feed country = country.encode('ascii', 'ignore') country = country.replace("Dem.", "Democratic") country = country.replace("Rep.", "Republic") country = country.replace("W.", "West") country = country.replace("Lao PDR", "Laos") country = country.replace("Bosnia and Herz.", "Bosnia and Herzegovina") country = country.replace("Eq. Guinea", "Equatorial Guinea") country = country.replace("Cte d'Ivoire", "Ivory Coast") country = country.replace("Fr. S. Antarctic Lands", "French Southern and Antarctic Lands") country = country.replace("Is.", "Islands") country = country.replace("S. Sudan", "South Sudan") country = country.replace(" ", "_") print country url1 = "http://api.feedzilla.com/v1/categories/19/articles/search.atom?q=" + country + "&count=50" feed = Feed(url1) # url2="http://api.feedzilla.com/v1/categories/26/articles/search.atom?q="+country+"&count=10" # feed.add_feed(url2) # feed = Feed() # feed.load() # feed.filter_country(country) feed.extract() return feed.to_json()
def articles(): from feed import Feed # feed = Feed('data/2014-04-05_16-54.atom') feed = Feed() feed.load() return feed.to_json()
def __init__(self): Base.__init__(self) self.style_sheets.append('css/feed.css') self.javascript_src.extend(['js/tags.js', 'js/feed.js']) self.feed = Feed(self) self.debug_cgi = 0
def __init__(self): with open(CONFIG_FILE_PATH) as config: self.config = json.load(config) self.loop = asyncio.get_event_loop() self.queue = deque() self.db = DataStore() self.feed = Feed(self.config, self.db) self.guideDog = GuideDog(self.config, self.db) self.run_flag = True
def get_feed(): chapters = Chapter.lookup_chapters() feed = Feed(flask.request.url_root) for chapter in chapters: feed.add_chapter(chapter) resp = flask.make_response(feed.rss(), 200) # set the header resp.headers['content-type'] = 'application/rss+xml' return resp
def test_default_values(self): feed_req_obj = Feed(None, None, '220', 'EBAY_US', 'v^1 ...') self.assertEqual(feed_req_obj.feed_type, FeedType.ITEM.value) self.assertEqual(feed_req_obj.feed_scope, FeedScope.DAILY.value) self.assertTrue(feed_req_obj.token.startswith('Bearer'), 'Bearer is missing from token') self.assertEqual(feed_req_obj.feed_date, get_formatted_date(feed_req_obj.feed_type)) self.assertEqual(feed_req_obj.environment, Environment.PRODUCTION.value) self.assertEqual(feed_req_obj.download_location, DEFAULT_DOWNLOAD_LOCATION) self.assertEqual(feed_req_obj.file_format, FileFormat.GZIP.value)
def test_dict_serialization(self): feed = Feed(self.test_name, self.test_uri) feed_dict = feed.to_dict() expected = {'name': self.test_name, 'uri': self.test_uri} self.assertEqual(feed_dict, expected) from_feed = Feed.from_dict(feed_dict) self.assertEqual(from_feed, feed) self.assertEqual(feed_dict, from_feed.to_dict())
def test_get_wall_own_post_and_newest_order(self): feed = Feed() own_message = "Message message message" feed.post_message("A", own_message) feed.follow("A", "B") B_msg = "it's your birthday" feed.post_message("B", B_msg) own_new_msg = "speechless" feed.post_message("A", own_new_msg) self.assertEqual([own_new_msg, B_msg, own_message], feed.get_wall_for("A"))
def index(): response.content_type = 'text/xml; charset=utf-8' page = Page(settings.URL) source = page.crawl() jobs = page.parse(source) feed = Feed(jobs) return feed.generate()
def channel(channel_id): channel = db.session.query(Channel).get(channel_id) if not channel: flask.abort(404) url, name = channel.feed.split('|') feed = Feed(url, name) feed.parse() return flask.render_template('channel.html', feed=feed, channel=channel)
def addlink(user_link, arr): try: new_feed = Feed(user_link) with open("links.txt", "a") as f: f.write(user_link) arr += new_feed.updated_feed except InvalidRSSError: print( "The RSS link either isn't up to standard or you didn't provide an RSS link. Please select another item." )
def _dict_to_feed_or_folder(node): if "children" in node: folder = Folder() folder.__dict__ = node return folder if "title" in node: feed = Feed() feed.__dict__ = node return feed return node
def __init__(self): """This class contais the logic of the UNO card game. """ self.players = [] self.draw_deck = Deck() self.discard_deck = Deck() self.colors = Config.CARD_COLORS self.wc_color = Config.SPECIAL_COLOR # wc = wildcard self.feed = Feed(50) self._init_game_variables()
def sources_post(): feed_url = request.form['feed'] # create new Feed object from feed_url try: feed_obj = Feed(feed_url) source = Source.insert_from_feed(feed_url, feed_obj.get_source()) # retrieve articles from the rss feed added by the form feed_articles = feed_obj.get_articles() Article.insert_from_feed(source.id, feed_articles) except: flash("Invalid Feed") return redirect('/sources')
def identifyFeed(self, feedUrl): # TODO: This should probably be done in a thread resourceFetcher = ResourceFetcher(feedUrl, self.proxy) feedText = resourceFetcher.getData() self.feed = Feed() try: root = etree.fromstring(feedText) except Exception as inst: if len(feedText) > 50: feedTextToDisplay = "<Feed text too large>" else: feedTextToDisplay = feedText errMsg = "parseFeed: Exception: {} when parsing feed item text:\n{}".format( inst, feedTextToDisplay) print(errMsg) logging.error(errMsg) return self.feed channel = root.find('channel') if channel is None: # Some feeds use 'feed' instead of 'channel' channel = root.find('feed') # Some feeds (ahem, GOOGLE!) don't have a channel or feed tag if channel is not None: feedRoot = channel else: feedRoot = root self.feed.m_feedUrl = feedUrl self.feed.m_feedTitle = getElementValue(feedRoot, ['title']) self.feed.m_feedName = self.feed.m_feedTitle # This field is deprecated, but is still being set self.feed.m_feedLanguage = getElementValue(feedRoot, ['language']) self.feed.m_feedDescription = getElementValue(feedRoot, ['description']) self.feed.m_feedWebPageLink = getElementValue(feedRoot, ['link']) self.feed.m_feedDateAdded = datetime.datetime.today() self.feed.m_feedLastUpdated = datetime.datetime( 1990, 1, 1) # Indicate it has never been updated self.feed.m_feedLastPurged = datetime.datetime( 1990, 1, 1) # Indicate it has never been purged self.readFeedImage(feedRoot) if self.feed.m_feedImage.isNull(): # The feed did not contain an image. Try getting the favicon from the feed's web site. self.getWebsiteFavicon() return self.feed
def guide(): channels = db.session.query(Channel).all() feeds = [] for channel in channels: url, name = channel.feed.split('|') feed = Feed(url, name) feed.parse() feed.channel = channel.name feeds.append(feed) return flask.render_template('guide.html', feeds=feeds)
def test_get_wall_messages_of_followed_user(self): feed = Feed() follower = "a" followed = "b" feed.follow(follower=follower, followed=followed) old_msg = "Sup?" feed.post_message(followed, old_msg) res = feed.get_wall_for(follower) self.assertEqual([old_msg], res) new_msg = "Busy day copy pasting from stackoverflow" feed.post_message(followed, new_msg) res = feed.get_wall_for(follower) self.assertEqual([new_msg, old_msg], res)