making this shit better one line at a time
This commit is contained in:
@ -6,7 +6,6 @@ NO_COLOR="\033[0m" # Text Reset
|
|||||||
IN_FILE="$1_generated.txt"
|
IN_FILE="$1_generated.txt"
|
||||||
SUCCESS_FILE="$1_success.txt"
|
SUCCESS_FILE="$1_success.txt"
|
||||||
FAIL_FILE="$1_failed.txt"
|
FAIL_FILE="$1_failed.txt"
|
||||||
BOOL_SUCCESS=0
|
|
||||||
|
|
||||||
if [[ $(hostname) == \s\a\t\a\n ]]; then
|
if [[ $(hostname) == \s\a\t\a\n ]]; then
|
||||||
[[ -d ./Artists ]] || mkdir ./Artists
|
[[ -d ./Artists ]] || mkdir ./Artists
|
||||||
@ -52,8 +51,8 @@ while IFS= read -r line; do
|
|||||||
path=$(echo "$line" | awk '{print $3}')
|
path=$(echo "$line" | awk '{print $3}')
|
||||||
|
|
||||||
download $url $path
|
download $url $path
|
||||||
|
|
||||||
exit
|
|
||||||
done < "$IN_FILE"
|
done < "$IN_FILE"
|
||||||
|
|
||||||
[[ $(hostname) != \s\a\t\a\n ]] && cp ./gallery-dl/archive-${$1,,}.sqlite3 /data/backup
|
[[ -s $FAIL_FILE ]] && curl -d 'bruh' ntfy.hopeless-cloud.xyz/Hentai
|
||||||
|
|
||||||
|
[[ $(hostname) != \s\a\t\a\n ]] && cp ./gallery-dl/archive-${1,,}.sqlite3 /data/backup
|
||||||
|
153
src/main.rs
153
src/main.rs
@ -2,12 +2,83 @@ use postgres::{Client, NoTls};
|
|||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::{BufRead, BufReader, Write},
|
io::{self, BufRead, BufReader, Write},
|
||||||
};
|
};
|
||||||
use urlencoding;
|
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 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
|
let output = client
|
||||||
.query_one("SELECT website_exists($1);", &[&website_name])
|
.query_one("SELECT website_exists($1);", &[&website_name])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -38,8 +109,17 @@ fn generate_file(website_name: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_folders(root_folder: &str) {
|
fn convert_folders(client: &mut postgres::Client, path: Option<String>) {
|
||||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
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 filename: &str = "convert_folders.log";
|
||||||
let mut log_file = match File::create(filename) {
|
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 input_file = File::open(filename).unwrap();
|
||||||
let reader_iter = BufReader::new(input_file).lines();
|
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") {
|
let mut fucked_file = match File::create("Fucked.txt") {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
@ -104,8 +194,18 @@ fn import_file(filename: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_url(url: &str) {
|
fn add_url(client: &mut postgres::Client, uri: Option<String>) {
|
||||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
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 output = client.query_one("SELECT insert_url($1);", &[&url]).unwrap();
|
||||||
|
|
||||||
let result: i32 = output.get(0);
|
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) {
|
fn add_artist_with_custom_name(client: &mut postgres::Client, uri_and_artist: Option<Vec<String>>) {
|
||||||
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap();
|
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
|
let output = client
|
||||||
.query_one(
|
.query_one(
|
||||||
"SELECT insert_url_with_custom_artist($1, $2);",
|
"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() {
|
fn main() {
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
dbg!(&args);
|
|
||||||
|
|
||||||
let option: &str = args[1].as_str();
|
if args.len() == 1 {
|
||||||
let value: &str = args[2].as_str();
|
run_as_cli();
|
||||||
|
} else {
|
||||||
match option {
|
run_with_input(args);
|
||||||
"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"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user