remove rust

This commit is contained in:
2025-05-04 21:35:47 +02:00
parent f31a5a4d4d
commit b505e4ba3d
3 changed files with 0 additions and 1178 deletions

View File

@ -1,286 +0,0 @@
use postgres::{Client, NoTls};
use std::{
env::args,
error::Error,
fs::{self, File},
io::{self, BufRead, BufReader, Write},
};
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(client: &mut postgres::Client) -> Result<(), Box<dyn Error>> {
show_usage();
println!("Please input any of these options or type \'exit\' to leave\n");
loop {
let mut option = String::new();
io::stdin().read_line(&mut option)?;
match option.trim_end() {
"usage" => show_usage(),
"generate" => generate_file(client, None, None)?,
"convert" => convert_folders(client, None)?,
"import" => import_file(client, None)?,
"add_url" => add_url(client, None)?,
"add_custom_name" => add_artist_with_custom_name(client, None)?,
"exit" => {
return Ok(());
}
_ => {
eprintln!("Invalid option!");
}
};
println!("Done!");
}
}
fn run_with_input(
client: &mut postgres::Client,
arguments: Vec<String>,
) -> Result<(), Box<dyn Error>> {
if arguments[1] == "usage" {
show_usage();
return Ok(());
}
let value = arguments[2].clone();
match arguments[1].as_str() {
"generate" => generate_file(
client,
Option::Some(value),
Option::Some(arguments[3].clone()),
)?,
"convert" => convert_folders(client, Option::Some(value))?,
"import" => import_file(client, Option::Some(value))?,
"add_url" => add_url(client, Option::Some(value))?,
"add_custom_name" => {
let values = (arguments[2].clone(), arguments[3].clone());
add_artist_with_custom_name(client, Option::Some(values))?
}
_ => {
return Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid argument",
)));
}
};
// println!("Done!");
Ok(())
}
fn generate_file(
client: &mut postgres::Client,
website: Option<String>,
folder_path: Option<String>,
) -> Result<(), Box<dyn Error>> {
let mut website_name = String::new();
let mut file_path = String::new();
match website {
Some(val) => website_name = val,
None => {
println!(
"Please input the desired website name. Options currently are (Rule34, Iwara)"
);
io::stdin().read_line(&mut website_name)?;
}
};
website_name = website_name.trim().to_string();
match folder_path {
Some(val) => file_path = val,
None => {
println!("Please input the folder_path of where to save the file");
io::stdin().read_line(&mut file_path)?;
}
};
file_path = file_path.trim().to_string();
file_path.push_str(format!("/{website_name}_generated.txt").as_str());
let output = client.query_one("SELECT website_exists($1);", &[&website_name])?;
let found: bool = output.get(0);
if !found {
return Err(Box::new(io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid website_name",
)));
}
let mut file = File::create(file_path)?;
let output = client.query("SELECT * FROM get_urls_and_paths($1);", &[&website_name])?;
for row in output {
let url: String = row.get(0);
let folder_path: String = row.get(1);
writeln!(file, "{} # data/{}", url, folder_path)?;
}
Ok(())
}
fn convert_folders(
client: &mut postgres::Client,
path: Option<String>,
) -> Result<(), Box<dyn Error>> {
let mut root_folder = String::new();
match path {
Some(val) => root_folder = val,
None => {
println!("Please input the desired path to where your files live");
io::stdin().read_line(&mut root_folder)?;
}
};
let root_folder = root_folder.trim();
let filename = "convert_folders.log";
let mut log_file = File::create_new(filename)?;
let output = client.query("SELECT * FROM get_all_convertable_paths();", &[])?;
for row in output {
let old_path: String = row.get(0);
let new_path: String = row.get(1);
let old_path = format!("{}/{}", root_folder, old_path);
let new_path = format!("{}/{}", root_folder, new_path);
let old_path = urlencoding::decode(&old_path)?.to_string();
dbg!(&old_path);
dbg!(&new_path);
if fs::exists(&old_path)? {
fs::rename(&old_path, &new_path)?;
writeln!(log_file, "Converted {} => {}", old_path, new_path)?;
}
}
Ok(())
}
fn import_file(client: &mut postgres::Client, file: Option<String>) -> Result<(), Box<dyn Error>> {
let mut filename = String::new();
match file {
Some(val) => filename = val,
None => {
println!("Please input the name of the desired file");
io::stdin().read_line(&mut filename)?;
}
};
let filename = filename.trim();
let input_file = File::open(filename)?;
let reader_iter = BufReader::new(input_file).lines();
if File::open("Fucked.txt").is_ok() {
if File::open("Fucked.txt.bak").is_ok() {
fs::remove_file("Fucked.txt.bak")?;
}
fs::rename("Fucked.txt", "Fucked.txt.bak")?;
}
let mut fucked_file = File::create_new("Fucked.txt")?;
writeln!(fucked_file, "Them are hella fucked")?;
for line in reader_iter {
let line = line?;
if line.contains("#") {
writeln!(fucked_file, "{}", line)?;
continue;
}
client.query_one("SELECT insert_url($1);", &[&line])?;
}
Ok(())
}
fn add_url(client: &mut postgres::Client, uri: Option<String>) -> Result<(), Box<dyn Error>> {
let mut url = String::new();
match uri {
Some(val) => url = val,
None => {
println!("Please input the desired url");
io::stdin().read_line(&mut url)?;
}
};
let url = url.trim();
let output = client.query_one("SELECT insert_url($1);", &[&url])?;
let something: String = output.get(0);
println!("{something}");
Ok(())
}
fn add_artist_with_custom_name(
client: &mut postgres::Client,
url_and_artist: Option<(String, String)>,
) -> Result<(), Box<dyn Error>> {
let mut url = String::new();
let mut artist_name = String::new();
match url_and_artist {
Some(tuple) => {
url = tuple.0;
artist_name = tuple.1;
}
None => {
println!("Please input the desired url");
io::stdin().read_line(&mut url)?;
println!("Please input the desired artist name");
io::stdin().read_line(&mut artist_name)?;
}
};
let url = url.trim();
let artist_name = artist_name.trim();
let output = client.query_one(
"SELECT insert_url_with_custom_artist($1, $2);",
&[&url, &artist_name],
)?;
let something: String = output.get(0);
println!("{something}");
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
let args = args().collect::<Vec<String>>();
let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls)?;
match args.len() {
1 => run_as_cli(&mut client)?,
_ => run_with_input(&mut client, args)?,
}
Ok(())
}