Make the database stuff more abstract
But only a bit
This commit is contained in:
parent
98490e7f75
commit
282d94bdd4
1 changed files with 14 additions and 9 deletions
|
@ -21,6 +21,15 @@ async def get_playlists(connection: Connection, user_email: str) -> list[Playlis
|
|||
p.index, p.title, p.description, p.privacy;
|
||||
"""
|
||||
|
||||
return create_playlists(await connection.fetch(sql, user_email))
|
||||
|
||||
async def export_user(connection: Connection, user_email: str) -> InvidiousJsonDataExport:
|
||||
data = await connection.fetchrow("SELECT subscriptions, watched, preferences FROM users WHERE email = $1", user_email)
|
||||
playlists = await get_playlists(connection, user_email)
|
||||
|
||||
return create_json_data_export(data, playlists)
|
||||
|
||||
def create_playlists(rows):
|
||||
return [
|
||||
Playlist(
|
||||
title=row['title'],
|
||||
|
@ -28,17 +37,13 @@ async def get_playlists(connection: Connection, user_email: str) -> list[Playlis
|
|||
privacy=PlaylistPrivacy[row['privacy']],
|
||||
video_ids=row['video_ids'] or []
|
||||
)
|
||||
for row in await connection.fetch(sql, user_email)
|
||||
for row in rows
|
||||
]
|
||||
|
||||
async def export_user(connection: Connection, user_email: str) -> InvidiousJsonDataExport:
|
||||
data = await connection.fetchrow("SELECT subscriptions, watched, preferences FROM users WHERE email = $1", user_email)
|
||||
|
||||
subscribed_channels_ids = data['subscriptions']
|
||||
watched_videos_ids = data['watched']
|
||||
user_preferences = json.loads(data['preferences'])
|
||||
|
||||
playlists = await get_playlists(connection, user_email)
|
||||
def create_json_data_export(row, playlists):
|
||||
subscribed_channels_ids = row['subscriptions']
|
||||
watched_videos_ids = row['watched']
|
||||
user_preferences = json.loads(row['preferences'])
|
||||
|
||||
data_export = InvidiousJsonDataExport(
|
||||
subscriptions = [Channel(id=c_id) for c_id in subscribed_channels_ids],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue