From b31cfb99aa657d2dca2895b9b5fe4c40d503ff65 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sun, 29 May 2022 15:16:48 +0000 Subject: [PATCH] add update_feed_items method --- database.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/database.py b/database.py index 5bf8478..38191aa 100644 --- a/database.py +++ b/database.py @@ -48,5 +48,13 @@ class Database(): return self.cur.fetchall() def find_feed_items(self, feed_id: int) -> list: - self.cur.execute('SELECT * FROM feeds_last_items WHERE feed_id = (?)', [feed_id]) - return self.cur.fetchall() \ No newline at end of file + self.cur.execute('SELECT * FROM feeds_last_items WHERE feed_id = ?', [feed_id]) + return self.cur.fetchall() + + def update_feed_items(self, feed_id: int, new_items: list) -> None: + for i in range(len(new_items)): + new_items[i] = (feed_id,) + new_items[i] + + self.cur.execute('DELETE FROM feeds_last_items WHERE feed_id = ?', [feed_id]) + self.cur.executemany('INSERT INTO feeds_last_items (feed_id, url, title, description, date) VALUES (?, ?, ?, ?, ?)', new_items) + self.conn.commit() \ No newline at end of file