mirror of
https://github.com/agresdominik/predictify.git
synced 2026-04-21 17:55:49 +00:00
Big commit
This commit is contained in:
+46
-4
@@ -71,10 +71,13 @@ class Database:
|
||||
|
||||
def add_row(self, table: Table, values):
|
||||
"""Add a new row into the specified table"""
|
||||
placeholders = ', '.join(['?'] * len(values))
|
||||
query = f"INSERT INTO {table.value} VALUES ({placeholders})"
|
||||
self.cursor.execute(query, values)
|
||||
self.conn.commit()
|
||||
try:
|
||||
placeholders = ', '.join(['?'] * len(values))
|
||||
query = f"INSERT INTO {table.value} VALUES ({placeholders})"
|
||||
self.cursor.execute(query, values)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
def read_all_rows(self, table: Table, column: str = "*"):
|
||||
"""Read all rows from the specified table"""
|
||||
@@ -85,3 +88,42 @@ class Database:
|
||||
def close(self):
|
||||
"""Close the database connection"""
|
||||
self.conn.close()
|
||||
|
||||
def get_total_overview(self) -> list:
|
||||
"""Retrieve a total overview of all recently played songs with full details"""
|
||||
try:
|
||||
# Join recently_played with track_information, artist_information, and album_information
|
||||
query = f'''
|
||||
SELECT rp.played_at,
|
||||
ti.track_id,
|
||||
ti.title,
|
||||
ai.artist_id,
|
||||
ai.artist_name,
|
||||
al.album_id,
|
||||
al.album_name
|
||||
FROM {Table.RECENTLY_PLAYED.value} rp
|
||||
JOIN {Table.TRACK_INFORMATION.value} ti ON rp.track_id = ti.track_id
|
||||
JOIN {Table.ARTIST_INFORMATION.value} ai ON rp.artist_id = ai.artist_id
|
||||
JOIN {Table.ALBUM_INFORMATION.value} al ON rp.album_id = al.album_id
|
||||
ORDER BY rp.played_at DESC
|
||||
'''
|
||||
self.cursor.execute(query)
|
||||
rows = self.cursor.fetchall()
|
||||
return rows
|
||||
except Exception as e:
|
||||
print(f"Error retrieving total overview: {e}")
|
||||
return []
|
||||
|
||||
"""
|
||||
print(rows)
|
||||
|
||||
if rows:
|
||||
print(f"{'Played At':<20} {'Track ID':<20} {'Track Title':<50} {'Artist ID':<20} {'Artist Name':<50} {'Album ID':<20} {'Album Name':<50}")
|
||||
print("-" * 160)
|
||||
for row in rows:
|
||||
played_at, track_id, title, artist_id, artist_name, album_id, album_name = row
|
||||
print(f"{played_at:<20} {track_id:<20} {title:<50} {artist_id:<20} {artist_name:<50} {album_id:<20} {album_name:<50}")
|
||||
else:
|
||||
print("No recently played songs found.")
|
||||
except Exception as e:
|
||||
print(f"Error retrieving total overview: {e}")"""
|
||||
|
||||
Reference in New Issue
Block a user