~roshless/nnrss

eaa309f2e3a71a5072be15a8ecef293f746e3457 — Roshless 5 months ago 4699b5e 1.3.1
bugfix: feed update

did not work because of little change in model, dont know if thats
a bug or my fault :/
1 files changed, 22 insertions(+), 22 deletions(-)

M nnrss/database.py
M nnrss/database.py => nnrss/database.py +22 -22
@@ 97,35 97,33 @@ class RssHandler:

    def __update_feed_by_id(self, feed_id):
        with self.__session_scope() as session:
            author = session.query(Feed).filter_by(id=feed_id).first()
            if not hasattr(author, "rss_link"):
            feed = session.query(Feed).filter(Feed.id == feed_id).first()
            if not hasattr(feed, "rss_link"):
                return False
            author_with_new_entries = self.__parse_feed(author.rss_link)
            if author_with_new_entries is None:
            parsed_entries = self.__parse_feed(feed.rss_link, only_entries=True)
            if parsed_entries is None:
                return False
            new_entries = [
                x
                for x in author_with_new_entries.entries
                if x not in set(author.entries)
                for x in parsed_entries
                if x not in set(feed.entries)
            ]
            author.entries.extend(new_entries)
            feed.entries.extend(new_entries)
            return True

    def __update_feed_by_id_and_username(self, feed_id, username):
        with self.__session_scope() as session:
            feed = (
                session.query(Feed)
                .join(User)
                .filter(User.username == username)
                .filter(Feed.id == feed_id)
                .first()
            )
            if not hasattr(feed, "rss_link"):
                return False
            feed_with_new_entries = self.__parse_feed(feed.rss_link)
            feed_with_new_entries.id_user = User.id
            parsed_entries = self.__parse_feed(feed.rss_link, only_entries=True)
            new_entries = [
                x for x in feed_with_new_entries.entries if x not in set(feed.entries)
                x for x in parsed_entries if x not in set(feed.entries)
            ]
            feed.updated_date = dt.utcnow()
            feed.entries.extend(new_entries)


@@ 281,7 279,7 @@ class RssHandler:
            return (True, feed_entry.link)

    @staticmethod
    def __parse_feed(rss_url):
    def __parse_feed(rss_url, only_entries=False):
        parsed = feedparser_parse(rss_url)
        feed_entries_list = []
        for entry in parsed.entries:


@@ 290,7 288,6 @@ class RssHandler:
            else:
                content = entry.summary

            from sys import stderr
            try:
                date=dt.fromtimestamp(mktime(entry.published_parsed))
            except AttributeError:


@@ 307,15 304,18 @@ class RssHandler:
                )
            )

        try:
            return Feed(
                title=parsed.feed.title,
                link=parsed.feed.link,
                rss_link=rss_url,
                entries=feed_entries_list,
            )
        except AttributeError:
            return None
        if not only_entries:
            try:
                return Feed(
                    title=parsed.feed.title,
                    link=parsed.feed.link,
                    rss_link=rss_url,
                    entries=feed_entries_list,
                )
            except AttributeError:
                return None
        else:
            return feed_entries_list

    """
    General rules: