From c9ae6dcc78f81de6c86e3b94f6feacd7624a495b Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sun, 29 May 2022 23:06:07 +0000 Subject: [PATCH] correct docstrings --- .gitignore | 2 +- database.py | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 8b2d7e0..4bb55d6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ /.venv # Database -/bot.db \ No newline at end of file +/*.db \ No newline at end of file diff --git a/database.py b/database.py index e7e14fb..f8f4542 100644 --- a/database.py +++ b/database.py @@ -5,14 +5,8 @@ Database - implement intercaction with the database. """ class Database(): - """ - Implement intercaction with the database. - - Methods: - add_user, find_user, add_feed, subscribe_user, - unsubscribe_user, delete_feed, find_feeds, - find_user_feeds, find_feed_items, update_feed_items. - """ + """Implement intercaction with the database.""" + def __init__(self, path: str) -> None: """Create a database file if not exists.""" self.conn = sqlite3.connect(path) @@ -23,13 +17,13 @@ class Database(): 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))') def add_user(self, telegram_id: str) -> int: - """Add a user's telegram id to the database and return his database id.""" + """Add a user's telegram id to the database and return its database id.""" self.cur.execute('INSERT INTO users (telegram_id) VALUES (?)', [telegram_id]) self.conn.commit() return self.cur.lastrowid def find_user(self, telegram_id: str) -> int | None: - """Get a user's telegram id and return his database id.""" + """Get a user's telegram id and return its database id.""" self.cur.execute('SELECT id FROM users WHERE telegram_id = ?', [telegram_id]) row = self.cur.fetchone() if row is None: @@ -37,7 +31,7 @@ class Database(): return row[0] def add_feed(self, url: str) -> int: - """Add a feed from to the database and return its id.""" + """Add a feed to the database and return its id.""" self.cur.execute('INSERT INTO feeds (url) VALUES (?)', [url]) self.conn.commit() return self.cur.lastrowid @@ -53,12 +47,12 @@ class Database(): self.conn.commit() def delete_feed(self, feed_id: int) -> None: - """Delete a feed from the database.""" + """Delete a feed.""" self.cur.execute('DELETE FROM feeds WHERE id = ?', [feed_id]) self.conn.commit() def find_feeds(self) -> list: - """Get a list of feeds from the database and returns it.""" + """Get a list of feeds.""" self.cur.execute('SELECT * FROM feeds') return self.cur.fetchall() @@ -68,12 +62,12 @@ class Database(): return self.cur.fetchall() def find_feed_items(self, feed_id: int) -> list: - """Get feed items and return it.""" + """Get last feed items.""" 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: - """Replace feed items from the database with a list items that receive.""" + """Replace last feed items with a list items that receive.""" for i in range(len(new_items)): new_items[i] = (feed_id,) + new_items[i]