def reset_errors(feed_id): feed_contr = FeedController(g.user.id) feed = feed_contr.get(id=feed_id) feed_contr.update({'id': feed_id}, {'error_count': 0, 'last_error': ''}) flash(gettext('Feed %(feed_title)r successfully updated.', feed_title=feed.title), 'success') return redirect(request.referrer or url_for('home'))
def reset_errors(feed_id): feed_contr = FeedController(current_user.id) feed = feed_contr.get(id=feed_id) feed_contr.update({'id': feed_id}, {'error_count': 0, 'last_error': ''}) flash( gettext('Feed %(feed_title)r successfully updated.', feed_title=feed.title), 'success') return redirect(request.referrer or url_for('home'))
def reset_feeds(): contr = FeedController() step = timedelta(seconds=3600 / contr.read().count()) now = datetime.utcnow() for i, feed in enumerate(contr.read() .order_by(contr._db_cls.last_retrieved)): contr.update({'id': feed.id}, {'etag': '', 'last_modified': '', 'last_retrieved': now - i * step})
def process_form(feed_id=None): form = AddFeedForm() feed_contr = FeedController(current_user.id) form.set_category_choices(CategoryController(current_user.id).read()) if not form.validate(): return render_template("edit_feed.html", form=form) existing_feeds = list(feed_contr.read(link=form.link.data)) if existing_feeds and feed_id is None: flash(gettext("Couldn't add feed: feed already exists."), "warning") return redirect(url_for("feed.form", feed_id=existing_feeds[0].id)) # Edit an existing feed feed_attr = { "title": form.title.data, "enabled": form.enabled.data, "link": form.link.data, "site_link": form.site_link.data, "filters": [], "category_id": form.category_id.data, "private": form.private.data, } if not feed_attr["category_id"] or feed_attr["category_id"] == "0": del feed_attr["category_id"] for filter_attr in ("type", "pattern", "action on", "action"): for i, value in enumerate( request.form.getlist(filter_attr.replace(" ", "_"))): if i >= len(feed_attr["filters"]): feed_attr["filters"].append({}) feed_attr["filters"][i][filter_attr] = value if feed_id is not None: feed_contr.update({"id": feed_id}, feed_attr) flash( gettext( "Feed %(feed_title)r successfully updated.", feed_title=feed_attr["title"], ), "success", ) return redirect(url_for("feed.form", feed_id=feed_id)) # Create a new feed new_feed = feed_contr.create(**feed_attr) flash( gettext("Feed %(feed_title)r successfully created.", feed_title=new_feed.title), "success", ) if conf.CRAWLING_METHOD == "default": misc_utils.fetch(current_user.id, new_feed.id) flash(gettext("Downloading articles for the new feed..."), "info") return redirect(url_for("feed.form", feed_id=new_feed.id))
def reset_errors(feed_id): feed_contr = FeedController(current_user.id) feed = feed_contr.get(id=feed_id) feed_contr.update({"id": feed_id}, {"error_count": 0, "last_error": ""}) flash( gettext("Feed %(feed_title)r successfully updated.", feed_title=feed.title), "success", ) return redirect(request.referrer or url_for("home"))
def reset_feeds(): contr = FeedController() step = timedelta(seconds=3600 / contr.read().count()) now = datetime.utcnow() for i, feed in enumerate(contr.read().order_by( contr._db_cls.last_retrieved)): contr.update({'id': feed.id}, { 'etag': '', 'last_modified': '', 'last_retrieved': now - i * step })
def process_form(feed_id=None): form = AddFeedForm() feed_contr = FeedController(current_user.id) form.set_category_choices(CategoryController(current_user.id).read()) if not form.validate(): return render_template('edit_feed.html', form=form) existing_feeds = list(feed_contr.read(link=form.link.data)) if existing_feeds and feed_id is None: flash(gettext("Couldn't add feed: feed already exists."), "warning") return redirect(url_for('feed.form', feed_id=existing_feeds[0].id)) # Edit an existing feed feed_attr = { 'title': form.title.data, 'enabled': form.enabled.data, 'link': form.link.data, 'site_link': form.site_link.data, 'filters': [], 'category_id': form.category_id.data, 'private': form.private.data } if not feed_attr['category_id'] or feed_attr['category_id'] == '0': del feed_attr['category_id'] for filter_attr in ('type', 'pattern', 'action on', 'action'): for i, value in enumerate( request.form.getlist(filter_attr.replace(' ', '_'))): if i >= len(feed_attr['filters']): feed_attr['filters'].append({}) feed_attr['filters'][i][filter_attr] = value if feed_id is not None: feed_contr.update({'id': feed_id}, feed_attr) flash( gettext('Feed %(feed_title)r successfully updated.', feed_title=feed_attr['title']), 'success') return redirect(url_for('feed.form', feed_id=feed_id)) # Create a new feed new_feed = feed_contr.create(**feed_attr) flash( gettext('Feed %(feed_title)r successfully created.', feed_title=new_feed.title), 'success') if conf.CRAWLING_METHOD == "default": misc_utils.fetch(current_user.id, new_feed.id) flash(gettext("Downloading articles for the new feed..."), 'info') return redirect(url_for('feed.form', feed_id=new_feed.id))
def process_form(feed_id=None): form = AddFeedForm() feed_contr = FeedController(current_user.id) form.set_category_choices(CategoryController(current_user.id).read()) if not form.validate(): return render_template('edit_feed.html', form=form) existing_feeds = list(feed_contr.read(link=form.link.data)) if existing_feeds and feed_id is None: flash(gettext("Couldn't add feed: feed already exists."), "warning") return redirect(url_for('feed.form', feed_id=existing_feeds[0].id)) # Edit an existing feed feed_attr = {'title': form.title.data, 'enabled': form.enabled.data, 'link': form.link.data, 'site_link': form.site_link.data, 'filters': [], 'category_id': form.category_id.data, 'private': form.private.data} if not feed_attr['category_id'] or feed_attr['category_id'] == '0': del feed_attr['category_id'] for filter_attr in ('type', 'pattern', 'action on', 'action'): for i, value in enumerate( request.form.getlist(filter_attr.replace(' ', '_'))): if i >= len(feed_attr['filters']): feed_attr['filters'].append({}) feed_attr['filters'][i][filter_attr] = value if feed_id is not None: feed_contr.update({'id': feed_id}, feed_attr) flash(gettext('Feed %(feed_title)r successfully updated.', feed_title=feed_attr['title']), 'success') return redirect(url_for('feed.form', feed_id=feed_id)) # Create a new feed new_feed = feed_contr.create(**feed_attr) flash(gettext('Feed %(feed_title)r successfully created.', feed_title=new_feed.title), 'success') if conf.CRAWLING_METHOD == "classic": misc_utils.fetch(current_user.id, new_feed.id) flash(gettext("Downloading articles for the new feed..."), 'info') return redirect(url_for('feed.form', feed_id=new_feed.id))
def test_create_using_filters(self): feed_ctr = FeedController(2) feed1 = feed_ctr.read()[0].dump() feed2 = feed_ctr.read()[1].dump() feed3 = feed_ctr.read()[2].dump() feed_ctr.update({'id': feed1['id']}, {'filters': [{"type": "simple match", "pattern": "no see pattern", "action on": "match", "action": "mark as read"}]}) feed_ctr.update({'id': feed3['id']}, {'filters': [{"type": "regex", "pattern": ".*(pattern1|pattern2).*", "action on": "no match", "action": "mark as favorite"}, {"type": "simple match", "pattern": "no see pattern", "action on": "match", "action": "mark as read"}]}) art1 = ArticleController(2).create( entry_id="thisisnotatest", feed_id=feed1['id'], title="garbage no see pattern garbage", content="doesn't matter", link="doesn't matter either") art2 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed1['id'], title="garbage see pattern garbage", content="doesn't matter2", link="doesn't matter either2") art3 = ArticleController(2).create( entry_id="thisisnotatest", user_id=2, feed_id=feed2['id'], title="garbage no see pattern garbage", content="doesn't matter", link="doesn't matter either") art4 = ArticleController(2).create( entry_id="thisisnotatesteither", user_id=2, feed_id=feed2['id'], title="garbage see pattern garbage", content="doesn't matter2", link="doesn't matter either2") art5 = ArticleController(2).create( entry_id="thisisnotatest", feed_id=feed3['id'], title="garbage pattern1 garbage", content="doesn't matter", link="doesn't matter either") art6 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage pattern2 garbage", content="doesn't matter2", link="doesn't matter either2") art7 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage no see pattern3 garbage", content="doesn't matter3", link="doesn't matter either3") art8 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage pattern4 garbage", content="doesn't matter4", link="doesn't matter either4") self.assertTrue(art1.readed) self.assertFalse(art1.like) self.assertFalse(art2.readed) self.assertFalse(art2.like) self.assertFalse(art3.readed) self.assertFalse(art3.like) self.assertFalse(art4.readed) self.assertFalse(art4.like) self.assertFalse(art5.readed) self.assertFalse(art5.like) self.assertFalse(art6.readed) self.assertFalse(art6.like) self.assertTrue(art7.readed) self.assertTrue(art7.like) self.assertFalse(art8.readed) self.assertTrue(art8.like)
def test_create_using_filters(self): feed_ctr = FeedController(2) feed1 = feed_ctr.read()[0].dump() feed2 = feed_ctr.read()[1].dump() feed3 = feed_ctr.read()[2].dump() feed_ctr.update({'id': feed1['id']}, {'filters': [{"type": "simple match", "pattern": "no see pattern", "action on": "match", "action": "mark as read"}]}) feed_ctr.update({'id': feed3['id']}, {'filters': [{"type": "regex", "pattern": ".*(pattern1|pattern2).*", "action on": "no match", "action": "mark as favorite"}, {"type": "simple match", "pattern": "no see pattern", "action on": "match", "action": "mark as read"}]}) art1 = ArticleController(2).create( entry_id="thisisnotatest", feed_id=feed1['id'], title="garbage no see pattern garbage", content="doesn't matter", link="doesn't matter either") art2 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed1['id'], title="garbage see pattern garbage", content="doesn't matter2", link="doesn't matter either2") art3 = ArticleController(2).create( entry_id="thisisnotatest", user_id=2, feed_id=feed2['id'], title="garbage no see pattern garbage", content="doesn't matter", link="doesn't matter either") art4 = ArticleController(2).create( entry_id="thisisnotatesteither", user_id=2, feed_id=feed2['id'], title="garbage see pattern garbage", content="doesn't matter2", link="doesn't matter either2") art5 = ArticleController(2).create( entry_id="thisisnotatest", feed_id=feed3['id'], title="garbage pattern1 garbage", content="doesn't matter", link="doesn't matter either") art6 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage pattern2 garbage", content="doesn't matter2", link="doesn't matter either2") art7 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage no see pattern3 garbage", content="doesn't matter3", link="doesn't matter either3") art8 = ArticleController(2).create( entry_id="thisisnotatesteither", feed_id=feed3['id'], title="garbage pattern4 garbage", content="doesn't matter4", link="doesn't matter either4") self.assertTrue(art1.readed) self.assertFalse(art1.like) self.assertFalse(art2.readed) self.assertFalse(art2.like) self.assertFalse(art3.readed) self.assertFalse(art3.like) self.assertFalse(art4.readed) self.assertFalse(art4.like) self.assertFalse(art5.readed) self.assertFalse(art5.like) self.assertFalse(art6.readed) self.assertFalse(art6.like) self.assertTrue(art7.readed) self.assertTrue(art7.like) self.assertFalse(art8.readed) self.assertTrue(art8.like)