From dc3889635e74a52ab55fa3d3483d824cab8e7a8d Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sun, 29 May 2022 14:18:07 +0000 Subject: [PATCH] add find_feed_items method and rename get_feeds to find_feeds, get_user_feeds to find_user_feeds methods --- database.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/database.py b/database.py index 2ed0774..5bf8478 100644 --- a/database.py +++ b/database.py @@ -8,6 +8,7 @@ class Database(): self.cur.execute('CREATE TABLE IF NOT EXISTS subscriptions (user_id INTEGER, feed_id INTEGER, FOREIGN KEY(user_id) REFERENCES users(id), FOREIGN KEY(feed_id) REFERENCES feeds(id))') self.cur.execute('CREATE UNIQUE INDEX IF NOT EXISTS subscriptions_index ON subscriptions (user_id, feed_id)') self.cur.execute('CREATE TABLE IF NOT EXISTS feeds_last_items (feed_id INTEGER, url TEXT NOT NULL UNIQUE, title TEXT, description TEXT, date NUMERIC, FOREIGN KEY(feed_id) REFERENCES feeds(id))') + self.cur.execute('CREATE UNIQUE INDEX IF NOT EXISTS feed_item_index ON feeds_last_items (feed_id, date)') def add_user(self, telegram_id: str) -> int: self.cur.execute('INSERT INTO users (telegram_id) VALUES (?)', [telegram_id]) @@ -38,16 +39,14 @@ class Database(): self.cur.execute('DELETE FROM feeds WHERE id = ?', [feed_id]) self.conn.commit() - def get_feeds(self) -> list: + def find_feeds(self) -> list: self.cur.execute('SELECT * FROM feeds') return self.cur.fetchall() - def get_user_feeds(self, user_id: int) -> list: + def find_user_feeds(self, user_id: int) -> list: self.cur.execute('SELECT * FROM feeds WHERE id IN (SELECT feed_id FROM subscriptions WHERE user_id = ?)', [user_id]) return self.cur.fetchall() - def get_feed_items(): - pass - - def storing_feed_content(): - pass \ No newline at end of file + 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