diff options
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/lib/utils.py | 7 | ||||
-rw-r--r-- | pyaggr3g470r/templates/home.html | 2 | ||||
-rw-r--r-- | pyaggr3g470r/views/feed.py | 11 |
3 files changed, 15 insertions, 5 deletions
diff --git a/pyaggr3g470r/lib/utils.py b/pyaggr3g470r/lib/utils.py index b7e5cafc..280256f6 100644 --- a/pyaggr3g470r/lib/utils.py +++ b/pyaggr3g470r/lib/utils.py @@ -1,5 +1,6 @@ import types import urllib +import base64 import logging import requests from hashlib import md5 @@ -41,8 +42,10 @@ def rebuild_url(url, base_split): def try_splits(url, *splits): for split in splits: - if requests.get(rebuild_url(url, split), verify=False).ok: - return rebuild_url(url, split) + rb_url = rebuild_url(url, split) + response = requests.get(rb_url, verify=False, timeout=10) + if response.ok and 'html' not in response.headers['content-type']: + return base64.b64encode(response.content).decode('utf8') return None diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index 7e272b55..42a5d498 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -106,7 +106,7 @@ {% endif %} </td> <td><a class="open-article" href="/article/redirect/{{ article.id}}" target="_blank"> - {% if article.source.icon %}<img src="{{ article.source.icon }}" width="16px" />{% endif %} + {% if article.source.icon %}<img src="{{ url_for('feed.icon', feed_id=article.feed_id) }}" width="16px" />{% endif %} <span class="hidden-xs">{{ article.source.title|safe }}</span></a></td> <td {%if filter_ == 'all' and article.readed == False %}style='font-weight:bold'{% endif %}> <a href="/article/{{ article.id }}">{{ article.title|safe }}</a> 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/<int:feed_id>', methods=['GET']) +def icon(feed_id): + return Response(base64.b64decode(FeedController().get(id=feed_id).icon), + mimetype='image') |