def index(): """ Displays an index page with the feed listing """ # get all the stuff we want feeds = Feed.objects() feed_count = feeds.count() topics = set([feed.category for feed in Feed.objects.only('category')]) feeds_topics_counts = len(topics) # TODO: probably should put this in the database along with the feed. feed_icons = { 'gaming': 'fa fa-gamepad', 'design': 'fa fa-building-o', 'business': 'fa fa-briefcase', 'cinema': 'fa fa-video-camera', 'data-science': 'fa fa-area-chart', 'cooking': 'fa fa-cutlery', 'sports': 'fa fa-futbol-o', 'books': 'fa fa-book', 'tech': 'fa fa-cogs', 'politics': 'fa fa-university', 'news': 'fa fa-newspaper-o', 'essays': 'fa fa-pencil-square-o', 'do-it-yourself': 'fa fa-wrench' } feeds_topics = {topic: Feed.objects(category=topic) for topic in topics} # load all the data into the templates/feed_list.html template return render_template('index.html', feeds=feeds, feeds_topics=feeds_topics, feed_count=feed_count, topic_count=feeds_topics_counts, feed_icons=feed_icons)
def index(): """ Displays an index page with the feed listing """ # get all the stuff we want feeds = Feed.objects() feed_count = feeds.count() topics = set([feed.category for feed in Feed.objects.only('category')]) feeds_topics_counts = len(topics) feeds_topics = {topic: Feed.objects(category=topic) for topic in topics} # load all the data into the templates/feed_list.html template return render_template('index.html', feeds=feeds, feeds_topics=feeds_topics, feed_count=feed_count, topic_count=feeds_topics_counts)
def feedinfo(self, path): """ Writes information about the feeds to disk for performing lookups on the feeds themselves from the object id in each individual post. """ fields = ('id', 'title', 'link', 'category', 'active') feeds = Feed.objects(category__in=self.categories).only(*fields) with open(path, 'w') as f: f.write(feeds.to_json(indent=2))
def test_load_opml_integrated(self): """ Test the integration of the ingest helper function """ self.assertEqual(Feed.objects.count(), 0) self.assertEqual(load_opml(FEEDLY), 36) self.assertEqual(Feed.objects.count(), 36) for feed in Feed.objects(): self.assertIn('xmlUrl', feed.urls) self.assertIn('htmlUrl', feed.urls)
def feeds(self, categories=None): """ Returns a list of feeds for the specified categories """ if isinstance(categories, basestring): categories = [categories] elif categories is None: categories = self.categories for category in categories: for feed in Feed.objects(category=category): yield feed
def feeds(self, categories=None): """ Returns a list of feeds for the specified categories. During export, this list is used to construct a feed-category mapping that is used to perform checking of sequential reads of Posts. """ if isinstance(categories, basestring): categories = [categories] elif categories is None: categories = self.categories else: categories = list(categories) return Feed.objects(category__in=categories)
def index(): """ Displays an index page with the feed listing """ # get all the stuff we want feeds = Feed.objects() feed_count = feeds.count() topics = set([feed.category for feed in Feed.objects.only('category')]) feeds_topics_counts = len(topics) # TODO: probably should put this in the database along with the feed. feed_icons = {'gaming':'fa fa-gamepad', 'design':'fa fa-building-o', 'business':'fa fa-briefcase', 'cinema':'fa fa-video-camera', 'data-science':'fa fa-area-chart', 'cooking':'fa fa-cutlery', 'sports':'fa fa-futbol-o', 'books':'fa fa-book', 'tech':'fa fa-cogs', 'politics':'fa fa-university', 'news':'fa fa-newspaper-o', 'essays':'fa fa-pencil-square-o', 'do-it-yourself':'fa fa-wrench' } feeds_topics = { topic: Feed.objects(category=topic) for topic in topics } # load all the data into the templates/feed_list.html template return render_template('index.html', feeds=feeds, feeds_topics=feeds_topics, feed_count=feed_count, topic_count=feeds_topics_counts, feed_icons=feed_icons)
except ImportError: import mock from baleen.wrangle import * from baleen.exceptions import * from baleen.models import Feed, Post ########################################################################## ## Fixtures ########################################################################## FIXTURES = os.path.join(os.path.dirname(__file__), "fixtures") RESULT = os.path.join(FIXTURES, "feedparser_result.pickle") FEED = Feed( title='The Rumpus.net', link='http://therumpus.net/feed/', urls={'htmlurl': 'http://therumpus.net'}, category='books', ) def mocked_requests_get(*args, **kwargs): class MockResponse: def __init__(self, text, status_code): self.text = text self.status_code = status_code def raise_for_status(self): if self.status_code != 200: raise Exception("HTTP {}".format(self.status_code)) text = "Luke, I am your father!"
except ImportError: import mock from baleen.wrangle import * from baleen.exceptions import * from baleen.models import Feed, Post ########################################################################## ## Fixtures ########################################################################## FIXTURES = os.path.join(os.path.dirname(__file__), "fixtures") RESULT = os.path.join(FIXTURES, "feedparser_result.pickle") FEED = Feed( title=u'The Rumpus.net', link=u'http://therumpus.net/feed/', urls={u'htmlurl': u'http://therumpus.net'}, category=u'books', ) def mocked_requests_get(*args, **kwargs): class MockResponse: def __init__(self, text, status_code): self.text = text self.status_code = status_code def raise_for_status(self): if self.status_code != 200: raise Exception("HTTP {}".format(self.status_code)) text = "Luke, I am your father!"