From d08cc46087d3349aff7b06908c70d97fecbdec8f Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sun, 5 Jul 2015 16:38:26 +0200 Subject: constructing feed from normal url also --- pyaggr3g470r/views/feed.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 8bd2f8e9..d31aa212 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -12,6 +12,7 @@ from flask.ext.login import login_required import conf from pyaggr3g470r import utils +from pyaggr3g470r.lib.utils import construct_feed_from from pyaggr3g470r.forms import AddFeedForm from pyaggr3g470r.controllers import FeedController, ArticleController @@ -94,14 +95,14 @@ def bookmarklet(): flash(gettext("Couldn't add feed: url missing."), "error") raise BadRequest("url is missing") - existing_feeds = list(feed_contr.read(link=url)) - if existing_feeds: + feed_exists = list(feed_contr.read(__or__={'link': url, 'site_link': url})) + if feed_exists: flash(gettext("Couldn't add feed: feed already exists."), "warning") return redirect(url_for('feed.form', feed_id=existing_feeds[0].id)) - feed = feed_contr.create(link=url) + feed = feed_contr.create(**construct_feed_from(url)) flash(gettext('Feed was successfully created.'), 'success') if conf.CRAWLING_METHOD == "classic": utils.fetch(g.user.id, feed.id) -- cgit From c1551acb30513f96d0053b96e240da7ab68833d2 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sun, 5 Jul 2015 17:41:06 +0200 Subject: making bookmaklet work for any url --- pyaggr3g470r/views/feed.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index d31aa212..224e27fb 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # -*- coding: utf-8 - - +import logging from datetime import datetime from sqlalchemy import desc from werkzeug.exceptions import BadRequest @@ -99,8 +99,7 @@ def bookmarklet(): if feed_exists: flash(gettext("Couldn't add feed: feed already exists."), "warning") - return redirect(url_for('feed.form', - feed_id=existing_feeds[0].id)) + return redirect(url_for('feed.form', feed_id=feed_exists[0].id)) feed = feed_contr.create(**construct_feed_from(url)) flash(gettext('Feed was successfully created.'), 'success') -- cgit From 75df52051b167425adcfb68797f77fcbcad33c4e Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Mon, 6 Jul 2015 10:28:58 +0200 Subject: light refact * both crawlers now use the same utils methods * the original crawler use now more of the controllers, enabling the filters feature --- pyaggr3g470r/views/feed.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 224e27fb..4c848b0e 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -1,6 +1,5 @@ #! /usr/bin/env python # -*- coding: utf-8 - -import logging from datetime import datetime from sqlalchemy import desc from werkzeug.exceptions import BadRequest @@ -12,7 +11,7 @@ from flask.ext.login import login_required import conf from pyaggr3g470r import utils -from pyaggr3g470r.lib.utils import construct_feed_from +from pyaggr3g470r.lib.feed.utils import construct_feed_from from pyaggr3g470r.forms import AddFeedForm from pyaggr3g470r.controllers import FeedController, ArticleController -- cgit From c47e8fbd86eebd4c61888b1cba6cf39670679fd0 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Mon, 6 Jul 2015 11:47:45 +0200 Subject: the icon isn't a url but a b64 dump --- pyaggr3g470r/views/feed.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index 4c848b0e..d84a68bc 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -1,17 +1,18 @@ #! /usr/bin/env python # -*- coding: utf-8 - +import base64 from datetime import datetime from sqlalchemy import desc from werkzeug.exceptions import BadRequest from flask import Blueprint, g, render_template, flash, \ - redirect, request, url_for + redirect, request, url_for, Response from flask.ext.babel import gettext from flask.ext.login import login_required import conf from pyaggr3g470r import utils -from pyaggr3g470r.lib.feed.utils import construct_feed_from +from pyaggr3g470r.lib.feed_utils import construct_feed_from from pyaggr3g470r.forms import AddFeedForm from pyaggr3g470r.controllers import FeedController, ArticleController @@ -182,3 +183,9 @@ def process_form(feed_id=None): flash(gettext("Downloading articles for the new feed..."), 'info') return redirect(url_for('feed.form', feed_id=new_feed.id)) + + +@feed_bp.route('/icon/', methods=['GET']) +def icon(feed_id): + return Response(base64.b64decode(FeedController().get(id=feed_id).icon), + mimetype='image') -- cgit From da4a415176c5d91a2310666ab597224591d3957c Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Mon, 6 Jul 2015 14:20:21 +0200 Subject: adding cache control on icons --- pyaggr3g470r/views/feed.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'pyaggr3g470r/views') diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py index d84a68bc..3556d7c7 100644 --- a/pyaggr3g470r/views/feed.py +++ b/pyaggr3g470r/views/feed.py @@ -1,6 +1,7 @@ #! /usr/bin/env python # -*- coding: utf-8 - import base64 +from hashlib import md5 from datetime import datetime from sqlalchemy import desc from werkzeug.exceptions import BadRequest @@ -186,6 +187,11 @@ def process_form(feed_id=None): @feed_bp.route('/icon/', methods=['GET']) +@login_required def icon(feed_id): - return Response(base64.b64decode(FeedController().get(id=feed_id).icon), - mimetype='image') + icon = FeedController(g.user.id).get(id=feed_id).icon + etag = md5(icon.encode('utf8')).hexdigest() + headers = {'Cache-Control': 'max-age=86400', 'ETag': etag} + if request.headers.get('if-none-match') == etag: + return Response(status=304, headers=headers) + return Response(base64.b64decode(icon), mimetype='image', headers=headers) -- cgit