summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/.ignore1
-rw-r--r--rust/Cargo.toml1
-rw-r--r--rust/scripts/create_db.sh5
-rw-r--r--rust/scripts/create_user.sql4
-rw-r--r--rust/scripts/populate.sh13
-rw-r--r--rust/scripts/populate/.gitignore (renamed from scrap/.gitignore)0
-rw-r--r--rust/scripts/populate/albums.py (renamed from scrap/albums.py)0
-rw-r--r--rust/scripts/populate/api.py (renamed from scrap/api.py)0
-rw-r--r--rust/scripts/populate/create_db.sql (renamed from scrap/create_db.sql)3
-rw-r--r--rust/scripts/populate/database.py (renamed from scrap/database.py)0
-rw-r--r--rust/scripts/populate/main.py (renamed from scrap/main.py)0
-rw-r--r--rust/scripts/populate/parser.py (renamed from scrap/parser.py)7
-rw-r--r--rust/scripts/populate/structures.py (renamed from scrap/structures.py)3
13 files changed, 31 insertions, 6 deletions
diff --git a/rust/.ignore b/rust/.ignore
new file mode 100644
index 0000000..0b68341
--- /dev/null
+++ b/rust/.ignore
@@ -0,0 +1 @@
+# scripts/populate/
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index bc8db03..b4a8000 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -11,6 +11,7 @@ tokio = "1.40.0"
[package.metadata.scripts]
db_create = "bash ./scripts/create_db.sh"
+db_populate = "bash ./scripts/populate.sh"
# db_start = "sudo docker start sqlx"
# db_start = "sudo docker stop sqlx"
# db_remove = "sudo docker rm sqlx"
diff --git a/rust/scripts/create_db.sh b/rust/scripts/create_db.sh
index cddcdd9..4e6ebc1 100644
--- a/rust/scripts/create_db.sh
+++ b/rust/scripts/create_db.sh
@@ -1,10 +1,11 @@
#!/bin/bash
-echo "choose a password for the database: 'input;"
+echo "choose a password for the database:"
read input
-echo $(pwd)
echo "creating database..."
sudo mariadb -u root <<EOF
$(cat scripts/create_user.sql)
EOF
+echo '$input'
+
sudo mariadb -u root < ./scripts/create_db.sql
diff --git a/rust/scripts/create_user.sql b/rust/scripts/create_user.sql
index b2eaaaa..bc9472b 100644
--- a/rust/scripts/create_user.sql
+++ b/rust/scripts/create_user.sql
@@ -1 +1,3 @@
-CREATE USER IF NOT EXISTS 'balalaika_user'@'%' IDENTIFIED BY '$input';
+DROP USER IF EXISTS 'balalaika_user'@'%';
+DROP USER IF EXISTS 'balalaika_user'@'localhost';
+CREATE USER 'balalaika_user'@'%' IDENTIFIED BY '$input';
diff --git a/rust/scripts/populate.sh b/rust/scripts/populate.sh
new file mode 100644
index 0000000..d8ccf8d
--- /dev/null
+++ b/rust/scripts/populate.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+echo activate virtual environment? \(source ~/.venv/bin/activate\) [y/n]
+read answer
+
+if [[ $answer == 'y' ]] then
+ source ~/.venv/bin/activate
+fi
+
+python3 scripts/populate/main.py
+
+if [[ $answer == 'y' ]] then
+ deactivate
+fi
diff --git a/scrap/.gitignore b/rust/scripts/populate/.gitignore
index 6922c3e..6922c3e 100644
--- a/scrap/.gitignore
+++ b/rust/scripts/populate/.gitignore
diff --git a/scrap/albums.py b/rust/scripts/populate/albums.py
index 63114da..63114da 100644
--- a/scrap/albums.py
+++ b/rust/scripts/populate/albums.py
diff --git a/scrap/api.py b/rust/scripts/populate/api.py
index 5cc24d3..5cc24d3 100644
--- a/scrap/api.py
+++ b/rust/scripts/populate/api.py
diff --git a/scrap/create_db.sql b/rust/scripts/populate/create_db.sql
index bb5dbeb..cfde7b0 100644
--- a/scrap/create_db.sql
+++ b/rust/scripts/populate/create_db.sql
@@ -15,8 +15,9 @@ CREATE TABLE artist (
CREATE TABLE album (
id int NOT NULL AUTO_INCREMENT,
name varchar(255),
- cover varchar(510),
+ cover varchar(255),
artist_id int,
+ release DATE,
PRIMARY KEY (id),
FOREIGN KEY (artist_id) REFERENCES artist(id)
diff --git a/scrap/database.py b/rust/scripts/populate/database.py
index 2319812..2319812 100644
--- a/scrap/database.py
+++ b/rust/scripts/populate/database.py
diff --git a/scrap/main.py b/rust/scripts/populate/main.py
index ec0157c..ec0157c 100644
--- a/scrap/main.py
+++ b/rust/scripts/populate/main.py
diff --git a/scrap/parser.py b/rust/scripts/populate/parser.py
index c447a0d..cbb51b5 100644
--- a/scrap/parser.py
+++ b/rust/scripts/populate/parser.py
@@ -27,8 +27,13 @@ def process_json(album_json, album_id, artist_id):
new_cover = get_cover_link(artist_id, album_id)
download_cover(off_cover, new_cover, artist_id)
+ year = data["release_date_components"]["year"]
+ month = data["release_date_components"]["year"]
+ day = data["release_date_components"]["year"]
+ release = [year, month, day]
+
songs = [analyze_song(song) for song in data["tracks"]]
- return structures.album(album_name, new_cover, songs, artist_id)
+ return structures.album(album_name, new_cover, songs, artist_id, release)
def get_cover_link(artist_id, album_id):
diff --git a/scrap/structures.py b/rust/scripts/populate/structures.py
index b139489..31feb1b 100644
--- a/scrap/structures.py
+++ b/rust/scripts/populate/structures.py
@@ -5,8 +5,9 @@ class song:
class album:
- def __init__(self, name, cover, songs, artist_id):
+ def __init__(self, name, cover, songs, artist_id, release=None):
self.name = name
self.cover = cover
self.songs = songs
self.artist = artist_id
+ self.release = release