~cedric/newspipe

8da441568d2f73054e41f8a9c8f11d80cb362165 — C├ędric Bonhomme a month ago 7d29e62
ensures that a feed always have a link: when adding a new feed or importing an account.
3 files changed, 10 insertions(+), 0 deletions(-)

M newspipe/controllers/feed.py
M newspipe/lib/data.py
M newspipe/lib/feed_utils.py
M newspipe/controllers/feed.py => newspipe/controllers/feed.py +3 -0
@@ 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)


M newspipe/lib/data.py => newspipe/lib/data.py +4 -0
@@ 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()

M newspipe/lib/feed_utils.py => newspipe/lib/feed_utils.py +3 -0
@@ 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