making this shit better one line at a time
This commit is contained in:
153
src/main.rs
153
src/main.rs
@ -2,12 +2,83 @@ use postgres::{Client, NoTls};
|
||||
use std::{
|
||||
env::args,
|
||||
fs::{self, File},
|
||||
io::{BufRead, BufReader, Write},
|
||||
io::{self, BufRead, BufReader, Write},
|
||||
};
|
||||
use urlencoding;
|
||||
|
||||
fn generate_file(website_name: &str) {
|
||||
fn show_usage() {
|
||||
println!("Available options:");
|
||||
println!("usage");
|
||||
println!("generate");
|
||||
println!("convert");
|
||||
println!("import");
|
||||
println!("add_url");
|
||||
println!("add_custom_name");
|
||||
}
|
||||
|
||||
fn run_as_cli() {
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
let mut option: String = String::new();
|
||||
|
||||
loop {
|
||||
show_usage();
|
||||
println!("Please input any of these options or type \'exit\' to leave");
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut option)
|
||||
.expect("Failed to read input");
|
||||
|
||||
let option: &str = option.trim_end(); // to get rid of '\n'
|
||||
|
||||
match option {
|
||||
"usage" => show_usage(),
|
||||
"generate" => generate_file(&mut client, None),
|
||||
"convert" => convert_folders(&mut client, None),
|
||||
"import" => import_file(&mut client, None),
|
||||
"add_url" => add_url(&mut client, None),
|
||||
"add_custom_name" => add_artist_with_custom_name(&mut client, None),
|
||||
"exit" => break,
|
||||
_ => {
|
||||
println!("Invalid option!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_with_input(arguments: Vec<String>) {
|
||||
if arguments[1] == "usage" {
|
||||
show_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
let value: String = arguments[2].clone();
|
||||
|
||||
match arguments[1].as_str() {
|
||||
"generate" => generate_file(&mut client, Option::Some(value)),
|
||||
"convert" => convert_folders(&mut client, Option::Some(value)),
|
||||
"import" => import_file(&mut client, Option::Some(value)),
|
||||
"add_url" => add_url(&mut client, Option::Some(value)),
|
||||
"add_custom_name" => {
|
||||
let values: Vec<String> = vec![arguments[2].clone(), arguments[3].clone()];
|
||||
add_artist_with_custom_name(&mut client, Option::Some(values))
|
||||
}
|
||||
_ => panic!("Invalid argument"),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_file(client: &mut postgres::Client, website: Option<String>) {
|
||||
let mut website_name: String = String::new();
|
||||
|
||||
match website {
|
||||
Some(val) => website_name = val,
|
||||
None => {
|
||||
io::stdin()
|
||||
.read_line(&mut website_name)
|
||||
.expect("Failed to read input");
|
||||
}
|
||||
};
|
||||
|
||||
let output = client
|
||||
.query_one("SELECT website_exists($1);", &[&website_name])
|
||||
.unwrap();
|
||||
@ -38,8 +109,17 @@ fn generate_file(website_name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_folders(root_folder: &str) {
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
fn convert_folders(client: &mut postgres::Client, path: Option<String>) {
|
||||
let mut root_folder: String = String::new();
|
||||
|
||||
match path {
|
||||
Some(val) => root_folder = val,
|
||||
None => {
|
||||
io::stdin()
|
||||
.read_line(&mut root_folder)
|
||||
.expect("Failed to read input");
|
||||
}
|
||||
};
|
||||
|
||||
let filename: &str = "convert_folders.log";
|
||||
let mut log_file = match File::create(filename) {
|
||||
@ -74,10 +154,20 @@ fn convert_folders(root_folder: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn import_file(filename: &str) {
|
||||
fn import_file(client: &mut postgres::Client, file: Option<String>) {
|
||||
let mut filename: String = String::new();
|
||||
|
||||
match file {
|
||||
Some(val) => filename = val,
|
||||
None => {
|
||||
io::stdin()
|
||||
.read_line(&mut filename)
|
||||
.expect("Failed to read input");
|
||||
}
|
||||
};
|
||||
|
||||
let input_file = File::open(filename).unwrap();
|
||||
let reader_iter = BufReader::new(input_file).lines();
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
|
||||
let mut fucked_file = match File::create("Fucked.txt") {
|
||||
Ok(file) => file,
|
||||
@ -104,8 +194,18 @@ fn import_file(filename: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_url(url: &str) {
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
fn add_url(client: &mut postgres::Client, uri: Option<String>) {
|
||||
let mut url: String = String::new();
|
||||
|
||||
match uri {
|
||||
Some(val) => url = val,
|
||||
None => {
|
||||
io::stdin()
|
||||
.read_line(&mut url)
|
||||
.expect("Failed to read input");
|
||||
}
|
||||
};
|
||||
|
||||
let output = client.query_one("SELECT insert_url($1);", &[&url]).unwrap();
|
||||
|
||||
let result: i32 = output.get(0);
|
||||
@ -114,8 +214,26 @@ fn add_url(url: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_artist_with_custom_name(url: &str, artist_name: &str) {
|
||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
||||
fn add_artist_with_custom_name(client: &mut postgres::Client, uri_and_artist: Option<Vec<String>>) {
|
||||
let mut url: String = String::new();
|
||||
let mut artist_name: String = String::new();
|
||||
|
||||
match uri_and_artist {
|
||||
Some(vec) => {
|
||||
url = vec[0].clone();
|
||||
artist_name = vec[1].clone();
|
||||
}
|
||||
None => {
|
||||
io::stdin()
|
||||
.read_line(&mut url)
|
||||
.expect("Failed to read input");
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut artist_name)
|
||||
.expect("Failed to read input");
|
||||
}
|
||||
};
|
||||
|
||||
let output = client
|
||||
.query_one(
|
||||
"SELECT insert_url_with_custom_artist($1, $2);",
|
||||
@ -131,17 +249,10 @@ fn add_artist_with_custom_name(url: &str, artist_name: &str) {
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = args().collect();
|
||||
dbg!(&args);
|
||||
|
||||
let option: &str = args[1].as_str();
|
||||
let value: &str = args[2].as_str();
|
||||
|
||||
match option {
|
||||
"generate" => generate_file(value),
|
||||
"convert" => convert_folders(value),
|
||||
"import" => import_file(value),
|
||||
"add_url" => add_url(value),
|
||||
"add_custom_name" => add_artist_with_custom_name(value, args[3].as_str()),
|
||||
_ => panic!("Invalid argument"),
|
||||
if args.len() == 1 {
|
||||
run_as_cli();
|
||||
} else {
|
||||
run_with_input(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user