aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-10-23 23:33:16 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-10-23 23:33:16 +0200
commit8da441568d2f73054e41f8a9c8f11d80cb362165 (patch)
tree5ae453ad96b1f617ac469b636351cd177bc213de
parentchg: [API] allow search with filters from controllers for articles. (diff)
downloadnewspipe-8da441568d2f73054e41f8a9c8f11d80cb362165.tar.gz
newspipe-8da441568d2f73054e41f8a9c8f11d80cb362165.tar.bz2
newspipe-8da441568d2f73054e41f8a9c8f11d80cb362165.zip
ensures that a feed always have a link: when adding a new feed or importing an account.
-rw-r--r--newspipe/controllers/feed.py3
-rw-r--r--newspipe/lib/data.py4
-rw-r--r--newspipe/lib/feed_utils.py3
3 files changed, 10 insertions, 0 deletions
diff --git a/newspipe/controllers/feed.py b/newspipe/controllers/feed.py
index 0f3f03e7..8a1b6b0b 100644
--- a/newspipe/controllers/feed.py
+++ b/newspipe/controllers/feed.py
@@ -88,6 +88,9 @@ class FeedController(AbstractController):
icon_contr.create(**{"url": attrs["icon_url"]})
def create(self, **attrs):
+ assert (
+ 'link' in attrs
+ ), "A feed must have a link."
self._ensure_icon(attrs)
return super().create(**attrs)
diff --git a/newspipe/lib/data.py b/newspipe/lib/data.py
index a335d040..d2698c8a 100644
--- a/newspipe/lib/data.py
+++ b/newspipe/lib/data.py
@@ -112,6 +112,8 @@ def import_json(nickname, json_content):
nb_feeds, nb_articles = 0, 0
# Create feeds:
for feed in json_account:
+ if 'link' not in feed.keys() or feed['link'] is None:
+ continue
if (
None
!= Feed.query.filter(
@@ -132,6 +134,8 @@ def import_json(nickname, json_content):
db.session.commit()
# Create articles:
for feed in json_account:
+ if 'link' not in feed.keys() or feed['link'] is None:
+ continue
user_feed = Feed.query.filter(
Feed.user_id == user.id, Feed.link == feed["link"]
).first()
diff --git a/newspipe/lib/feed_utils.py b/newspipe/lib/feed_utils.py
index 0de78580..6a072329 100644
--- a/newspipe/lib/feed_utils.py
+++ b/newspipe/lib/feed_utils.py
@@ -140,4 +140,7 @@ def construct_feed_from(url=None, fp_parsed=None, feed=None, query_site=True):
if len(alternates) >= 1:
feed["link"] = rebuild_url(alternates[0].attrs["href"], feed_split)
break
+ else:
+ assert feed.get("link", None) is not None
+
return feed
bgstack15