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