summaryrefslogtreecommitdiff
path: root/scrap
diff options
context:
space:
mode:
Diffstat (limited to 'scrap')
-rw-r--r--scrap/create_db.sql38
-rw-r--r--scrap/database.py47
-rw-r--r--scrap/main.py1
3 files changed, 39 insertions, 47 deletions
diff --git a/scrap/create_db.sql b/scrap/create_db.sql
new file mode 100644
index 0000000..bb5dbeb
--- /dev/null
+++ b/scrap/create_db.sql
@@ -0,0 +1,38 @@
+CREATE DATABASE IF NOT EXISTS balalaika;
+USE balalaika;
+
+DROP TABLE IF EXISTS song;
+DROP TABLE IF EXISTS album;
+DROP TABLE IF EXISTS artist;
+
+CREATE TABLE artist (
+ id int NOT NULL AUTO_INCREMENT,
+ name varchar(255),
+
+ PRIMARY KEY (id)
+);
+
+CREATE TABLE album (
+ id int NOT NULL AUTO_INCREMENT,
+ name varchar(255),
+ cover varchar(510),
+ artist_id int,
+
+ PRIMARY KEY (id),
+ FOREIGN KEY (artist_id) REFERENCES artist(id)
+);
+
+CREATE TABLE song (
+ id int NOT NULL AUTO_INCREMENT,
+ name varchar(255),
+ lyrics TEXT,
+
+ album_id int,
+
+ PRIMARY KEY (id),
+ FOREIGN KEY (album_id) REFERENCES album(id)
+);
+
+ALTER TABLE song CONVERT TO CHARACTER SET utf8;
+ALTER TABLE album CONVERT TO CHARACTER SET utf8;
+ALTER TABLE artist CONVERT TO CHARACTER SET utf8;
diff --git a/scrap/database.py b/scrap/database.py
index dab2592..d7c0e0c 100644
--- a/scrap/database.py
+++ b/scrap/database.py
@@ -3,57 +3,12 @@ import mysql.connector
connector = mysql.connector.connect(
host="localhost",
user="root",
+ database="balalaika",
)
cursor = connector.cursor()
-def setup():
- cursor.execute("CREATE DATABASE IF NOT EXISTS balalaika;")
- cursor.execute("USE balalaika;")
- cursor.execute("DROP TABLE IF EXISTS song;")
- cursor.execute("DROP TABLE IF EXISTS album;")
- cursor.execute("DROP TABLE IF EXISTS artist;")
-
- cursor.execute("""
- CREATE TABLE artist (
- id int NOT NULL AUTO_INCREMENT,
- name varchar(255),
-
- PRIMARY KEY (id)
- );
- """)
-
- cursor.execute("""
- CREATE TABLE album (
- id int NOT NULL AUTO_INCREMENT,
- name varchar(255),
- cover varchar(510),
- artist_id int,
-
- PRIMARY KEY (id),
- FOREIGN KEY (artist_id) REFERENCES artist(id)
- );
- """)
-
- cursor.execute("""
- CREATE TABLE song (
- id int NOT NULL AUTO_INCREMENT,
- name varchar(255),
- lyrics TEXT,
-
- album_id int,
-
- PRIMARY KEY (id),
- FOREIGN KEY (album_id) REFERENCES album(id)
- );
- """)
-
- cursor.execute("ALTER TABLE song CONVERT TO CHARACTER SET utf8")
- cursor.execute("ALTER TABLE album CONVERT TO CHARACTER SET utf8")
- cursor.execute("ALTER TABLE artist CONVERT TO CHARACTER SET utf8")
-
-
def process_albums(album_list):
[process_album(album, album_id)
for album_id, album in enumerate(album_list, 1)]
diff --git a/scrap/main.py b/scrap/main.py
index fbed3cd..ec0157c 100644
--- a/scrap/main.py
+++ b/scrap/main.py
@@ -9,7 +9,6 @@ def start():
api.download_albums(album_data)
print("uploading data...")
- database.setup()
upload_albums(
get_album_data(),
get_artist_names()