aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2022-01-02 01:19:19 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2022-01-02 01:19:19 +0100
commite206de09468fabcc5bcd83bd1de0ff656b8c8150 (patch)
tree23a372ac3e3d24840edd373e3399383bff10cf82
parentUpdated psycopg2-binary. (diff)
downloadnewspipe-e206de09468fabcc5bcd83bd1de0ff656b8c8150.tar.gz
newspipe-e206de09468fabcc5bcd83bd1de0ff656b8c8150.tar.bz2
newspipe-e206de09468fabcc5bcd83bd1de0ff656b8c8150.zip
various !minor fixes
-rw-r--r--.builds/debian.yml2
-rwxr-xr-xnewspipe/commands.py14
-rw-r--r--newspipe/controllers/feed.py2
-rw-r--r--newspipe/crawler/default_crawler.py10
-rw-r--r--newspipe/lib/article_utils.py4
-rw-r--r--newspipe/lib/data.py24
-rw-r--r--newspipe/lib/feed_utils.py2
-rwxr-xr-xnewspipe/lib/misc_utils.py8
-rw-r--r--newspipe/models/bookmark.py2
-rw-r--r--newspipe/web/lib/user_utils.py2
-rw-r--r--newspipe/web/views/__init__.py18
-rw-r--r--newspipe/web/views/article.py3
-rw-r--r--newspipe/web/views/bookmark.py1
-rw-r--r--newspipe/web/views/session_mgmt.py3
-rw-r--r--newspipe/web/views/user.py4
15 files changed, 56 insertions, 43 deletions
diff --git a/.builds/debian.yml b/.builds/debian.yml
index 54753607..33e7b185 100644
--- a/.builds/debian.yml
+++ b/.builds/debian.yml
@@ -20,4 +20,4 @@ tasks:
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
- poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
+ poetry run flake8 . --count --exit-zero --max-complexity=15 --max-line-length=105 --statistics
diff --git a/newspipe/commands.py b/newspipe/commands.py
index 335fa877..c7d7b71a 100755
--- a/newspipe/commands.py
+++ b/newspipe/commands.py
@@ -65,7 +65,8 @@ def delete_user(user_id=None):
@application.cli.command("delete_inactive_users")
@click.option("--last-seen", default=6, help="Number of months since last seen.")
def delete_inactive_users(last_seen):
- "Delete inactive users (inactivity is given in parameter and specified in number of months)."
+ """Delete inactive users (inactivity is given in parameter and specified in number
+ of months)."""
filter = {}
filter["last_seen__lt"] = date.today() - relativedelta(months=last_seen)
users = UserController().read(**filter)
@@ -74,7 +75,7 @@ def delete_inactive_users(last_seen):
try:
print("Deleting user {}...".format(user.nickname))
db.session.commit()
- except:
+ except Exception:
db.session.rollback()
print("Inactive users deleted.")
@@ -82,7 +83,8 @@ def delete_inactive_users(last_seen):
@application.cli.command("disable_inactive_users")
@click.option("--last-seen", default=6, help="Number of months since last seen.")
def disable_inactive_users(last_seen):
- "Disable inactive users (inactivity is given in parameter and specified in number of months)."
+ """Disable inactive users (inactivity is given in parameter and specified in number
+ of months)."""
filter = {}
filter["last_seen__lt"] = date.today() - relativedelta(months=last_seen)
users = UserController().read(**filter)
@@ -93,7 +95,7 @@ def disable_inactive_users(last_seen):
try:
print("Updating user {}...".format(user.nickname))
db.session.commit()
- except:
+ except Exception:
db.session.rollback()
print("Inactive users disabled.")
@@ -111,7 +113,7 @@ def delete_read_articles():
try:
db.session.delete(article)
db.session.commit()
- except:
+ except Exception:
db.session.rollback()
print("Read articles deleted.")
@@ -125,7 +127,7 @@ def fix_article_entry_id():
try:
article.entry_id = str(article.id)
db.session.commit()
- except:
+ except Exception:
db.session.rollback()
diff --git a/newspipe/controllers/feed.py b/newspipe/controllers/feed.py
index 513c5bd0..18f29906 100644
--- a/newspipe/controllers/feed.py
+++ b/newspipe/controllers/feed.py
@@ -24,7 +24,7 @@ class FeedController(AbstractController):
error_count__lt=max_error, enabled=True, last_retrieved__lt=max_last
)
.join(User)
- .filter(User.is_active == True)
+ .filter(User.is_active == True) # noqa
.order_by("last_retrieved")
.limit(limit)
]
diff --git a/newspipe/crawler/default_crawler.py b/newspipe/crawler/default_crawler.py
index 3b059202..7c8ce21e 100644
--- a/newspipe/crawler/default_crawler.py
+++ b/newspipe/crawler/default_crawler.py
@@ -39,7 +39,6 @@ from newspipe.controllers import ArticleController, FeedController
from newspipe.lib.article_utils import (
construct_article,
extract_id,
- get_article_content,
)
from newspipe.lib.feed_utils import construct_feed_from, is_parsing_ok
from newspipe.lib.utils import newspipe_get
@@ -98,14 +97,14 @@ async def parse_feed(user, feed):
# Feed information
try:
up_feed.update(construct_feed_from(feed.link, parsed_feed))
- except:
+ except Exception:
logger.exception("error when constructing feed: {}".format(feed.link))
if feed.title and "title" in up_feed:
# do not override the title set by the user
del up_feed["title"]
try:
FeedController().update({"id": feed.id}, up_feed)
- except:
+ except Exception:
logger.exception("error when updating feed: {}".format(feed.link))
return articles
@@ -172,9 +171,8 @@ async def retrieve_feed(queue, users, feed_id=None):
minutes=application.config["FEED_REFRESH_INTERVAL"]
)
# feeds = FeedController().read(**filters).all()
- feeds = (
- []
- ) # temporary fix for: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL SYSCALL error: EOF detected
+ feeds = [] # temporary fix for: sqlalchemy.exc.OperationalError:
+ # (psycopg2.OperationalError) SSL SYSCALL error: EOF detected
for feed in user.feeds:
if not feed.enabled:
continue
diff --git a/newspipe/lib/article_utils.py b/newspipe/lib/article_utils.py
index 6bf289c1..243aec5d 100644
--- a/newspipe/lib/article_utils.py
+++ b/newspipe/lib/article_utils.py
@@ -23,7 +23,7 @@ def extract_id(entry):
entry_id = "undefined"
try:
entry_id = entry.get("entry_id") or entry.get("id") or entry["link"]
- except:
+ except Exception:
pass
return entry_id
@@ -52,7 +52,7 @@ async def construct_article(entry, feed, fields=None, fetch=True):
logger.exception(
"Error when parsing date: {}".format(entry[date_key])
)
- except Exception as e:
+ except Exception:
pass
else:
break
diff --git a/newspipe/lib/data.py b/newspipe/lib/data.py
index 5654193f..0093c226 100644
--- a/newspipe/lib/data.py
+++ b/newspipe/lib/data.py
@@ -52,7 +52,7 @@ def import_opml(nickname, opml_content):
user = User.query.filter(User.nickname == nickname).first()
try:
subscriptions = opml.from_string(opml_content)
- except:
+ except Exception:
logger.exception("Parsing OPML file failed:")
raise
@@ -66,26 +66,26 @@ def import_opml(nickname, opml_content):
else:
try:
title = subscription.text
- except:
+ except Exception:
title = ""
try:
description = subscription.description
- except:
+ except Exception:
description = ""
try:
link = subscription.xmlUrl
- except:
+ except Exception:
continue
if (
- None
- != Feed.query.filter(
+ Feed.query.filter(
Feed.user_id == user.id, Feed.link == link
).first()
+ is not None
):
continue
try:
site_link = subscription.htmlUrl
- except:
+ except Exception:
site_link = ""
new_feed = Feed(
title=title,
@@ -115,10 +115,10 @@ def import_json(nickname, json_content):
if "link" not in feed.keys() or feed["link"] is None:
continue
if (
- None
- != Feed.query.filter(
+ Feed.query.filter(
Feed.user_id == user.id, Feed.link == feed["link"]
).first()
+ is not None
):
continue
new_feed = Feed(
@@ -139,15 +139,15 @@ def import_json(nickname, json_content):
user_feed = Feed.query.filter(
Feed.user_id == user.id, Feed.link == feed["link"]
).first()
- if None != user_feed:
+ if user_feed is not None:
for article in feed["articles"]:
if (
- None
- == Article.query.filter(
+ Article.query.filter(
Article.user_id == user.id,
Article.feed_id == user_feed.id,
Article.link == article["link"],
).first()
+ is not None
):
new_article = Article(
entry_id=article["link"],
diff --git a/newspipe/lib/feed_utils.py b/newspipe/lib/feed_utils.py
index 6a072329..47a32b43 100644
--- a/newspipe/lib/feed_utils.py
+++ b/newspipe/lib/feed_utils.py
@@ -92,7 +92,7 @@ def construct_feed_from(url=None, fp_parsed=None, feed=None, query_site=True):
return feed
except requests.exceptions.ConnectionError:
return feed
- except:
+ except Exception:
logger.exception("failed to retrieve %r", feed["site_link"])
return feed
bs_parsed = BeautifulSoup(
diff --git a/newspipe/lib/misc_utils.py b/newspipe/lib/misc_utils.py
index 243104a3..785b62db 100755
--- a/newspipe/lib/misc_utils.py
+++ b/newspipe/lib/misc_utils.py
@@ -46,7 +46,7 @@ from newspipe.lib.utils import clear_string
try:
from urlparse import urlparse, parse_qs, urlunparse
-except:
+except Exception:
from urllib.parse import urlparse, parse_qs, urlunparse, urljoin
@@ -119,14 +119,14 @@ def history(user_id, year=None, month=None):
"""
articles_counter = Counter()
articles = ArticleController(user_id).read()
- if None != year:
+ if year is not None:
articles = articles.filter(sqlalchemy.extract("year", "Article.date") == year)
- if None != month:
+ if month is not None:
articles = articles.filter(
sqlalchemy.extract("month", "Article.date") == month
)
for article in articles.all():
- if None != year:
+ if year is not None:
articles_counter[article.date.month] += 1
else:
articles_counter[article.date.year] += 1
diff --git a/newspipe/models/bookmark.py b/newspipe/models/bookmark.py
index 44bb429f..54c14536 100644
--- a/newspipe/models/bookmark.py
+++ b/newspipe/models/bookmark.py
@@ -28,13 +28,11 @@ __license__ = "GPLv3"
from datetime import datetime
-from sqlalchemy import desc
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import validates
from newspipe.bootstrap import db
from newspipe.models.right_mixin import RightMixin
-from newspipe.models.tag import BookmarkTag
class Bookmark(db.Model, RightMixin):
diff --git a/newspipe/web/lib/user_utils.py b/newspipe/web/lib/user_utils.py
index 22cf3b6a..1191fa8f 100644
--- a/newspipe/web/lib/user_utils.py
+++ b/newspipe/web/lib/user_utils.py
@@ -16,6 +16,6 @@ def confirm_token(token):
salt=application.config["SECURITY_PASSWORD_SALT"],
max_age=application.config["TOKEN_VALIDITY_PERIOD"],
)
- except:
+ except Exception:
return False
return nickname
diff --git a/newspipe/web/views/__init__.py b/newspipe/web/views/__init__.py
index beab0b52..950cb5b6 100644
--- a/newspipe/web/views/__init__.py
+++ b/newspipe/web/views/__init__.py
@@ -7,3 +7,21 @@ from newspipe.web.views.category import categories_bp, category_bp
from newspipe.web.views.feed import feed_bp, feeds_bp
from newspipe.web.views.icon import icon_bp
from newspipe.web.views.user import user_bp
+
+__all__ = [
+ "home",
+ "session_mgmt",
+ "views",
+ "admin_bp",
+ "v2",
+ "article_bp",
+ "articles_bp",
+ "bookmark_bp",
+ "bookmarks_bp",
+ "categories_bp",
+ "category_bp",
+ "feed_bp",
+ "feeds_bp",
+ "icon_bp",
+ "user_bp",
+]
diff --git a/newspipe/web/views/article.py b/newspipe/web/views/article.py
index 8cea11e4..a7d4fa93 100644
--- a/newspipe/web/views/article.py
+++ b/newspipe/web/views/article.py
@@ -3,7 +3,6 @@ from datetime import datetime, timedelta
from flask import (
Blueprint,
flash,
- g,
make_response,
redirect,
render_template,
@@ -14,7 +13,7 @@ from flask_babel import gettext
from flask_login import current_user, login_required
from newspipe.bootstrap import db
-from newspipe.controllers import ArticleController, CategoryController, UserController
+from newspipe.controllers import ArticleController, UserController
from newspipe.lib.data import export_json
from newspipe.lib.utils import clear_string, redirect_url
from newspipe.web.lib.view_utils import etag_match
diff --git a/newspipe/web/views/bookmark.py b/newspipe/web/views/bookmark.py
index 9d6a5725..de546b7d 100644
--- a/newspipe/web/views/bookmark.py
+++ b/newspipe/web/views/bookmark.py
@@ -40,7 +40,6 @@ from flask import (
from flask_babel import gettext
from flask_login import current_user, login_required
from flask_paginate import Pagination, get_page_args
-from sqlalchemy import desc, text
from werkzeug.exceptions import BadRequest
from newspipe.bootstrap import db
diff --git a/newspipe/web/views/session_mgmt.py b/newspipe/web/views/session_mgmt.py
index 90f3c141..8aa1cf60 100644
--- a/newspipe/web/views/session_mgmt.py
+++ b/newspipe/web/views/session_mgmt.py
@@ -7,11 +7,10 @@ from flask import (
flash,
redirect,
render_template,
- request,
session,
url_for,
)
-from flask_babel import gettext, lazy_gettext
+from flask_babel import gettext
from flask_login import LoginManager, current_user, login_required, logout_user
from flask_principal import (
AnonymousIdentity,
diff --git a/newspipe/web/views/user.py b/newspipe/web/views/user.py
index 6643cbca..c20777e7 100644
--- a/newspipe/web/views/user.py
+++ b/newspipe/web/views/user.py
@@ -101,7 +101,7 @@ def management():
Display the management page.
"""
if request.method == "POST":
- if None != request.files.get("opmlfile", None):
+ if None is not request.files.get("opmlfile", None):
# Import an OPML file
data = request.files.get("opmlfile", None)
if not misc_utils.allowed_file(data.filename):
@@ -115,7 +115,7 @@ def management():
flash(gettext("Downloading articles..."), "info")
except Exception:
flash(gettext("Impossible to import the new feeds."), "danger")
- elif None != request.files.get("jsonfile", None):
+ elif None is not request.files.get("jsonfile", None):
# Import an account
data = request.files.get("jsonfile", None)
if not misc_utils.allowed_file(data.filename):
bgstack15