summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/.gitignore5
-rw-r--r--rust/.ignore1
-rw-r--r--rust/Cargo.toml17
-rw-r--r--rust/N2
-rw-r--r--rust/env_example1
-rw-r--r--rust/scripts/create_db.sh11
-rw-r--r--rust/scripts/create_db.sql41
-rw-r--r--rust/scripts/create_user.sql3
-rw-r--r--rust/scripts/populate.sh13
-rw-r--r--rust/scripts/populate/.gitignore3
-rw-r--r--rust/scripts/populate/albums.py38
-rw-r--r--rust/scripts/populate/api.py21
-rw-r--r--rust/scripts/populate/create_db.sql39
-rw-r--r--rust/scripts/populate/database.py83
-rw-r--r--rust/scripts/populate/main.py46
-rw-r--r--rust/scripts/populate/parser.py83
-rw-r--r--rust/scripts/populate/structures.py13
-rw-r--r--rust/src/main.rs35
-rw-r--r--rust/src/routes.rs1
-rw-r--r--rust/src/routes/hello.rs11
-rw-r--r--rust/src/structs.rs35
21 files changed, 0 insertions, 502 deletions
diff --git a/rust/.gitignore b/rust/.gitignore
deleted file mode 100644
index 9adab75..0000000
--- a/rust/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-lock/
-target/
-Cargo.lock
-**/*.rs.bk
-.env
diff --git a/rust/.ignore b/rust/.ignore
deleted file mode 100644
index 0b68341..0000000
--- a/rust/.ignore
+++ /dev/null
@@ -1 +0,0 @@
-# scripts/populate/
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
deleted file mode 100644
index b4a8000..0000000
--- a/rust/Cargo.toml
+++ /dev/null
@@ -1,17 +0,0 @@
-[package]
-name = "ver1"
-version = "0.1.0"
-edition = "2021"
-
-[dependencies]
-actix-web = { version = "4.9.0"}
-sqlx = { version = "0.8.2", features = ["mysql", "macros", "runtime-tokio"] }
-serde = { version = "1.0.210", features = ["derive"] }
-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/N b/rust/N
deleted file mode 100644
index a755b9a..0000000
--- a/rust/N
+++ /dev/null
@@ -1,2 +0,0 @@
-cargo install cargo-run-script
-cargo-run-script db-create
diff --git a/rust/env_example b/rust/env_example
deleted file mode 100644
index 607b7cc..0000000
--- a/rust/env_example
+++ /dev/null
@@ -1 +0,0 @@
-DATABASE_URL="mysql://balalaika_user:password@127.0.0.1:3306/balalaika"
diff --git a/rust/scripts/create_db.sh b/rust/scripts/create_db.sh
deleted file mode 100644
index 4e6ebc1..0000000
--- a/rust/scripts/create_db.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-echo "choose a password for the database:"
-read input
-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_db.sql b/rust/scripts/create_db.sql
deleted file mode 100644
index f803714..0000000
--- a/rust/scripts/create_db.sql
+++ /dev/null
@@ -1,41 +0,0 @@
-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;
-
-GRANT ALL PRIVILEGES ON balalaika.* TO 'balalaika_user'@'%' WITH GRANT OPTION;
-FLUSH PRIVILEGES;
diff --git a/rust/scripts/create_user.sql b/rust/scripts/create_user.sql
deleted file mode 100644
index bc9472b..0000000
--- a/rust/scripts/create_user.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-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
deleted file mode 100644
index d8ccf8d..0000000
--- a/rust/scripts/populate.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/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/rust/scripts/populate/.gitignore b/rust/scripts/populate/.gitignore
deleted file mode 100644
index 6922c3e..0000000
--- a/rust/scripts/populate/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-__pycache__/
-*.json
-covers/
diff --git a/rust/scripts/populate/albums.py b/rust/scripts/populate/albums.py
deleted file mode 100644
index 63114da..0000000
--- a/rust/scripts/populate/albums.py
+++ /dev/null
@@ -1,38 +0,0 @@
-album_data = [
- ["astrophysics", [
- "apathy",
- "The Unending Need For Perpetual Motion",
- "HOPE LEFT ME Complete Version",
- "Selected Tragic",
- "Cute Tragedies",
- "selected apathetic",
- "ENTITY",
- ]],
- ["sadsvit", [
- "Неонова Мрія Neon Dream",
- "20 21",
- "Cassette",
- "Суматоха Bustle",
- ]],
- ["Молчат Дома", [
- "Белая Полоса White Stripe",
- "Монумент Monument",
- "Этажи Floors",
- "С крыш наших домов From our houses rooftops",
- ]],
- ["amesoeurs", [
- "Amesoeurs",
- ]],
- ["severoth", [
- "Vsesvit",
- "Winterfall",
- ]],
- ["sadness", [
- "Motionless Watching You",
- "Circle of Veins",
- ]],
- ["Буерак", [
- "Голд Gold",
- ]],
-
-]
diff --git a/rust/scripts/populate/api.py b/rust/scripts/populate/api.py
deleted file mode 100644
index 5cc24d3..0000000
--- a/rust/scripts/populate/api.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import lyricsgenius
-import parser
-import os
-
-
-genius = lyricsgenius.Genius(
- "0uSA9UFGsiO2WozVmbWPhyhOoVmUNuM3PXRt9rvWhptHBMgSO5CZBxGUMkwet5mv"
-)
-
-
-def download_albums(albums):
- [get_album_json(artist[0], album)
- for artist in albums for album in artist[1]]
-
-
-def get_album_json(artist_name, album_name):
- if os.path.isfile(parser.getLink(album_name)):
- return
-
- album = genius.search_album(album_name, artist_name)
- album.save_lyrics()
diff --git a/rust/scripts/populate/create_db.sql b/rust/scripts/populate/create_db.sql
deleted file mode 100644
index cfde7b0..0000000
--- a/rust/scripts/populate/create_db.sql
+++ /dev/null
@@ -1,39 +0,0 @@
-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(255),
- artist_id int,
- release DATE,
-
- 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/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()
diff --git a/rust/scripts/populate/main.py b/rust/scripts/populate/main.py
deleted file mode 100644
index ec0157c..0000000
--- a/rust/scripts/populate/main.py
+++ /dev/null
@@ -1,46 +0,0 @@
-from albums import album_data
-import api
-import parser
-import database
-
-
-def start():
- print("downloading data...")
- api.download_albums(album_data)
-
- print("uploading data...")
- upload_albums(
- get_album_data(),
- get_artist_names()
- )
- database.close()
- print("upload finished!")
- print("remember to move the covers directory once you're done")
-
-
-def upload_albums(album_data, artist_names):
- database.process_artists(artist_names)
- database.process_albums(album_data)
-
-
-def get_album_data():
- result = []
-
- for artist_id, artist in enumerate(album_data, 1):
- album_list = artist[1]
-
- for album_id, album in enumerate(album_list, 1):
- result.append(parser.process_json_file(album, album_id, artist_id))
-
- return result
-
-
-def get_artist_names():
- artist_data = []
- [artist_data.append(
- artist[0]
- ) for artist in album_data]
- return artist_data
-
-
-start()
diff --git a/rust/scripts/populate/parser.py b/rust/scripts/populate/parser.py
deleted file mode 100644
index cbb51b5..0000000
--- a/rust/scripts/populate/parser.py
+++ /dev/null
@@ -1,83 +0,0 @@
-import json
-import re
-import structures
-import os
-
-
-def process_json_file(name, album_id, artist_id):
- link = getLink(name)
-
- file_json = open(link, "r")
- album_json = file_json.read()
- file_json.close()
-
- return process_json(album_json, album_id, artist_id)
-
-
-def getLink(name):
- return "Lyrics_"+name.replace(" ", "")+".json"
-
-
-def process_json(album_json, album_id, artist_id):
- data = json.loads(album_json)
- album_name = data["name"].lower()
-
- off_cover = data["cover_art_thumbnail_url"]
-
- 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, release)
-
-
-def get_cover_link(artist_id, album_id):
- cover_link = f"covers/{artist_id}/{album_id}.png"
- return cover_link
-
-
-def download_cover(off_cover, new_cover, artist_id):
- if not os.path.isdir("covers"):
- os.system("mkdir covers")
-
- if not os.path.isdir(f"covers/{artist_id}"):
- os.system(f"mkdir 'covers/{artist_id}'")
-
- if not os.path.isfile(new_cover):
- os.system(f"wget {off_cover} -O '{new_cover}'")
-
-
-def analyze_song(song):
- name = song["song"]["title"]
- name = name.lower()
-
- lyrics = song["song"]["lyrics"]
- lyrics = format_lyrics(lyrics)
-
- return structures.song(name, lyrics)
-
-
-def format_lyrics(lyrics):
- if lyrics != "":
- lyrics = lyrics.split("Lyrics")[1].lstrip()
- lyrics = lyrics.split("Embed")[0].rstrip()
- lyrics = lyrics.replace("You might also like", "")
- lyrics = re.sub(r'See (.*?) LiveGet', 'liveget', lyrics)
- lyrics = lyrics.split("liveget")[0].rstrip()
-
- lyrics = re.sub(r'[\(\[].*?[\)\]]', '', lyrics)
- lyrics = re.sub("\n{3,}", "\n\n", lyrics)
-
- lyrics = lyrics.replace("\u2005", " ")
-
- while lyrics[0] == '\n':
- lyrics = lyrics[1:]
-
- lyrics = lyrics.lower()
-
- return lyrics
diff --git a/rust/scripts/populate/structures.py b/rust/scripts/populate/structures.py
deleted file mode 100644
index 31feb1b..0000000
--- a/rust/scripts/populate/structures.py
+++ /dev/null
@@ -1,13 +0,0 @@
-class song:
- def __init__(self, name, lyrics):
- self.name = name
- self.lyrics = lyrics
-
-
-class album:
- 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
diff --git a/rust/src/main.rs b/rust/src/main.rs
deleted file mode 100644
index af45779..0000000
--- a/rust/src/main.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-mod structs;
-mod routes;
-
-use actix_web::{web, App, HttpServer};
-use sqlx::mysql::{MySqlPool, MySqlPoolOptions};
-
-#[derive(Clone)]
-struct AppState {
- pool: MySqlPool,
-}
-
-#[actix_web::main]
-async fn main() -> std::io::Result<()> {
- let pool: MySqlPool = MySqlPoolOptions::new()
- .max_connections(10)
- .connect(DB_URL)
- .await
- .unwrap();
-
- let app_state = AppState { pool };
-
- HttpServer::new(move || {
- App::new()
- .app_data(web::Data::new(app_state.clone()))
- .route("/", web::get().to(root))
- .service(routes::hello::hello_actix)
- })
- .bind(("127.0.0.1", 8000))?
- .run()
- .await
-}
-
-async fn root() -> String {
- String::from("Server is up and running")
-}
diff --git a/rust/src/routes.rs b/rust/src/routes.rs
deleted file mode 100644
index 8cb6ff0..0000000
--- a/rust/src/routes.rs
+++ /dev/null
@@ -1 +0,0 @@
-mod hello;
diff --git a/rust/src/routes/hello.rs b/rust/src/routes/hello.rs
deleted file mode 100644
index c356081..0000000
--- a/rust/src/routes/hello.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use crate::AppState;
-use actix_web::{get, web, HttpResponse};
-use serde::Deserialize;
-
-#[get("/hello")]
-pub async fn hello_actix(app_state: web::Data<AppState>) -> HttpResponse {
- struct Song {
- }
-
- return HttpResponse::Ok().json(databases);
-}
diff --git a/rust/src/structs.rs b/rust/src/structs.rs
deleted file mode 100644
index 7535bb4..0000000
--- a/rust/src/structs.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-#[allow(dead_code)]
-struct Song {
- //song variables
- id: i32,
- title: String,
- lyrics: String,
-
- //album variables
- album_id: i32,
- genres: Vec<String>,
- album_cover: String,
-
- //artist variables
- artist_id: i32,
- artist_name: String,
-}
-
-#[allow(dead_code)]
-struct Album {
- id: i32,
- title: String,
- genres: Vec<String>,
- cover: String,
- songs: Vec<i32>,
-}
-
-#[allow(dead_code)]
-struct Artist {
- id: i32,
- name: String,
- genres: Vec<String>,
- albums: Vec<i32>,
-}
-
-// lepht anonym