add __convert_to_list_of_dicts method
This commit is contained in:
parent
5d0a6843b6
commit
feef909c61
19
database.py
19
database.py
|
@ -121,24 +121,24 @@ class Database:
|
|||
subscribers = self.cur.fetchall()
|
||||
return list(map(lambda x: x['telegram_id'], subscribers))
|
||||
|
||||
def find_feeds(self) -> list[DictRow]:
|
||||
def find_feeds(self) -> list[dict]:
|
||||
"""Get a list of feeds."""
|
||||
self.log.debug('find_feeds()')
|
||||
self.cur.execute('SELECT * FROM feeds')
|
||||
return self.cur.fetchall()
|
||||
return self.__convert_to_list_of_dicts(self.cur.fetchall())
|
||||
|
||||
def find_user_feeds(self, user_id: int) -> list[DictRow]:
|
||||
def find_user_feeds(self, user_id: int) -> list[dict]:
|
||||
"""Return a list of feeds the user is subscribed to."""
|
||||
self.log.debug('find_user_feeds(user_id=\'%s\')', user_id)
|
||||
self.cur.execute('SELECT * FROM feeds WHERE id IN (SELECT feed_id FROM subscriptions WHERE user_id = %s)',
|
||||
[user_id])
|
||||
return self.cur.fetchall()
|
||||
[user_id])
|
||||
return self.__convert_to_list_of_dicts(self.cur.fetchall())
|
||||
|
||||
def find_feed_items(self, feed_id: int) -> list[DictRow]:
|
||||
def find_feed_items(self, feed_id: int) -> list[dict]:
|
||||
"""Get last feed items."""
|
||||
self.log.debug('find_feed_items(feed_id=\'%s\')', feed_id)
|
||||
self.cur.execute('SELECT * FROM feeds_last_items WHERE feed_id = %s', [feed_id])
|
||||
return self.cur.fetchall()
|
||||
return self.__convert_to_list_of_dicts(self.cur.fetchall())
|
||||
|
||||
def find_feed_items_urls(self, feed_id: int) -> list[str]:
|
||||
"""Return urls last feed items"""
|
||||
|
@ -180,3 +180,8 @@ class Database:
|
|||
' description TEXT'
|
||||
')'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def __convert_to_list_of_dicts(rows: list[DictRow]) -> list[dict]:
|
||||
"""Convert list of DictRows to list of dicts"""
|
||||
return list(map(lambda x: dict(x), rows))
|
||||
|
|
Loading…
Reference in a new issue