aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/crawler.py38
-rw-r--r--pyaggr3g470r/decorators.py4
-rw-r--r--pyaggr3g470r/views.py18
3 files changed, 24 insertions, 36 deletions
diff --git a/pyaggr3g470r/crawler.py b/pyaggr3g470r/crawler.py
index ea149f5e..955d2144 100644
--- a/pyaggr3g470r/crawler.py
+++ b/pyaggr3g470r/crawler.py
@@ -29,40 +29,25 @@ __license__ = "AGPLv3"
import feedparser
import urllib2
import requests
-from requests.exceptions import *
-#from requests.packages.urllib3.exceptions import DecodeError
from datetime import datetime
+from requests.exceptions import *
import gevent.monkey
-#gevent.monkey.patch_socket()
gevent.monkey.patch_all()
from gevent import Timeout
-
from gevent.pool import Pool
-"""
-import logging
-logging.basicConfig()
-logging.getLogger().setLevel(logging.CRITICAL)
-requests_log = logging.getLogger("requests.packages.urllib3")
-requests_log.setLevel(logging.CRITICAL)
-requests_log.propagate = True
-"""
-
-
+import log
+import utils
import conf
+from pyaggr3g470r import db
+from pyaggr3g470r.models import User, Article
if not conf.ON_HEROKU:
import search as fastsearch
-import utils
-
-if not conf.ON_HEROKU:
from flask.ext.mail import Message
from pyaggr3g470r import mail
-from pyaggr3g470r import db
-from pyaggr3g470r.models import User, Article
-import log
pyaggr3g470r_log = log.Log("feedgetter")
@@ -105,7 +90,7 @@ class FeedGetter(object):
# 1 - Get the list of feeds to fetch
user = User.query.filter(User.email == self.user.email).first()
feeds = [feed for feed in user.feeds if feed.enabled]
- if feed_id != None:
+ if feed_id is not None:
feeds = [feed for feed in feeds if feed.id == feed_id]
# 2 - Fetch the feeds.
@@ -188,7 +173,8 @@ class FeedGetter(object):
description = BeautifulSoup(description, "html.parser").decode()
article_title = BeautifulSoup(article.title, "html.parser").decode()
except Exception:
- pyaggr3g470r_log.error("Problem when sanitizing the content of the article %s (%s)" % (article_title, nice_url))
+ pyaggr3g470r_log.error("Problem when sanitizing the content of the article %s (%s)" %
+ (article_title, nice_url))
article_title = article.title
try:
@@ -224,8 +210,9 @@ class FeedGetter(object):
exist = Article.query.filter(Article.user_id == self.user.id,
Article.feed_id == feed.id,
Article.link == article.link).first()
- if exist != None:
- pyaggr3g470r_log.error("Article %s (%s) already in the database." % (article.title, article.link))
+ if exist is not None:
+ pyaggr3g470r_log.error("Article %s (%s) already in the database." %
+ (article.title, article.link))
continue
try:
@@ -234,7 +221,8 @@ class FeedGetter(object):
db.session.commit()
pyaggr3g470r_log.info("New article %s (%s) added." % (article.title, article.link))
except IntegrityError:
- pyaggr3g470r_log.error("Article %s (%s) already in the database." % (article.title, article.link))
+ pyaggr3g470r_log.error("Article %s (%s) already in the database." %
+ (article.title, article.link))
db.session.rollback()
continue
except Exception as e:
diff --git a/pyaggr3g470r/decorators.py b/pyaggr3g470r/decorators.py
index a32e9709..0052dc80 100644
--- a/pyaggr3g470r/decorators.py
+++ b/pyaggr3g470r/decorators.py
@@ -24,9 +24,9 @@ def feed_access_required(func):
"""
@wraps(func)
def decorated(*args, **kwargs):
- if kwargs.get('feed_id', None) != None:
+ if kwargs.get('feed_id', None) is not None:
feed = Feed.query.filter(Feed.id == kwargs.get('feed_id', None)).first()
- if feed != None and (feed.subscriber.id == g.user.id or g.user.is_admin()):
+ if feed is not None and (feed.subscriber.id == g.user.id or g.user.is_admin()):
return func(*args, **kwargs)
flash("This feed do not exist.", "danger")
return redirect(url_for('home'))
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 02ef4f9e..6d394186 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -239,7 +239,7 @@ def article(article_id=None):
Presents the content of an article.
"""
article = Article.query.filter(Article.user_id == g.user.id, Article.id == article_id).first()
- if article != None:
+ if article is not None:
if not article.readed:
article.readed = True
db.session.commit()
@@ -256,7 +256,7 @@ def mark_as_read(feed_id=None):
"""
Mark all unreaded articles as read.
"""
- if feed_id != None:
+ if feed_id is not None:
Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed_id,
Article.readed == False).update({"readed": True})
flash('Articles marked as read.', 'info')
@@ -286,7 +286,7 @@ def delete(article_id=None):
Delete an article from the database.
"""
article = Article.query.filter(Article.id == article_id).first()
- if article != None and article.source.subscriber.id == g.user.id:
+ if article is not None and article.source.subscriber.id == g.user.id:
db.session.delete(article)
db.session.commit()
try:
@@ -296,7 +296,7 @@ def delete(article_id=None):
flash('Article "' + article.title + '" deleted.', 'success')
return redirect(url_for('home'))
else:
- flash('Impossible to delete the article.', 'danger')
+ flash('This article do not exist.', 'danger')
return redirect(url_for('home'))
@app.route('/articles/<feed_id>/', methods=['GET'])
@@ -441,7 +441,7 @@ def search():
nb_articles = 0
query = request.args.get('query', None)
- if query != None:
+ if query is not None:
try:
search_result, nb_articles = fastsearch.search(user.id, query)
except Exception as e:
@@ -511,7 +511,7 @@ def edit_feed(feed_id=None):
if request.method == 'POST':
if form.validate() == False:
return render_template('edit_feed.html', form=form)
- if feed_id != None:
+ if feed_id is not None:
# Edit an existing feed
form.populate_obj(feed)
db.session.commit()
@@ -534,7 +534,7 @@ def edit_feed(feed_id=None):
return redirect('/edit_feed/' + str(existing_feed[0].id))
if request.method == 'GET':
- if feed_id != None:
+ if feed_id is not None:
form = AddFeedForm(obj=feed)
return render_template('edit_feed.html', action="Edit the feed", form=form, feed=feed, \
not_on_heroku = not conf.ON_HEROKU)
@@ -608,7 +608,7 @@ def create_user(user_id=None):
if request.method == 'POST':
if form.validate():
- if user_id != None:
+ if user_id is not None:
# Edit a user
user = User.query.filter(User.id == user_id).first()
form.populate_obj(user)
@@ -632,7 +632,7 @@ def create_user(user_id=None):
return render_template('profile.html', form=form)
if request.method == 'GET':
- if user_id != None:
+ if user_id is not None:
user = User.query.filter(User.id == user_id).first()
form = ProfileForm(obj=user)
message = "Edit the user <i>" + user.firstname + "</i>"
bgstack15