diff options
author | nil <nil@tfwhyno.gf> | 2024-10-02 17:48:56 +0200 |
---|---|---|
committer | nil <nil@tfwhyno.gf> | 2024-10-02 17:48:56 +0200 |
commit | 0972fa6eab8c9111311f082ba8abfdc6b4a40945 (patch) | |
tree | 4eedbdc1a7cfdeee9d651c9871a9f26ab6da56d4 /rust/scripts/populate/database.py | |
parent | 012c2c03b29a987ca4eead023ded22e01aa7477b (diff) |
commit changes
Diffstat (limited to 'rust/scripts/populate/database.py')
-rw-r--r-- | rust/scripts/populate/database.py | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/rust/scripts/populate/database.py b/rust/scripts/populate/database.py deleted file mode 100644 index 2319812..0000000 --- a/rust/scripts/populate/database.py +++ /dev/null @@ -1,83 +0,0 @@ -import mysql.connector -import getpass - - -def get_database_password(): - return getpass.getpass("Insert database password: ") - - -connector = mysql.connector.connect( - host="localhost", - user="balalaika_user", - password=get_database_password(), - database="balalaika", -) - -cursor = connector.cursor() - - - - -def process_albums(album_list): - [process_album(album, album_id) - for album_id, album in enumerate(album_list, 1)] - - -def process_album(album, album_id): - upload_album(album) - [upload_song(song, album_id) for song in album.songs] - - -def upload_album(album): - album.name = album.name.lower() - cursor.execute(""" - INSERT INTO album ( - name, cover, artist_id - ) - VALUES ( - %(name)s, %(cover)s, %(artist_id)s - ); - """, { - 'name': album.name, - 'cover': album.cover, - 'artist_id': album.artist - }) - - -def upload_song(song, album_id): - cursor.execute(""" - INSERT INTO song ( - name, lyrics, album_id - ) - VALUES ( - %(name)s, %(lyrics)s, %(album_id)s - ) - """, { - 'name': song.name, - 'lyrics': song.lyrics, - 'album_id': album_id - }) - - -def process_artists(artist_names): - [process_artist(artist) for artist in artist_names] - - -def process_artist(artist): - artist = artist.lower() - cursor.execute(""" - INSERT INTO artist ( - name - ) - VALUES ( - %(name)s - ) - """, { - 'name': artist, - }) - - -def close(): - cursor.close() - connector.commit() - connector.close() |