diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b86eab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +*.csv \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ef282dd --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "booru_image_tag_curating_helper" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..983b026 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "booru_image_tag_curating_helper" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c60afb1 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,52 @@ +use std::{process::Command, io::{BufRead, Write}}; + +const LEGEND: &str = "[q]uit, [d]elete, [a]ccept"; +const PENDING: &str = "./pending.csv"; +const REJECTED: &str = "./rejected.csv"; +const VERIFIED: &str = "./verified.csv"; +fn main(){ + let file: String = std::fs::read(PENDING).expect("File not found").iter().map(|c| *c as char).collect(); + let mut file = file.lines(); + + while let Some(image_uri) = file.next(){ + //Open image + Command::new("xdg-open") + .arg(image_uri) + .spawn() + .expect("open command failed to start"); + //Print Legend + println!("{}", LEGEND); + // Wait for input + if input_parse(image_uri){ + std::fs::write(PENDING, format!("{}\n{}", image_uri, file.map(|s| s.to_owned() + "\n").collect::())).unwrap(); + std::process::exit(0); + } + } + std::fs::write(PENDING, "").unwrap(); +} + + +fn input_parse(image_uri: &str) -> bool { + let key = std::io::stdin().lock().lines().next().unwrap().unwrap().chars().next().unwrap_or('n'); + match key { + 'a' => { + let mut file = std::fs::OpenOptions::new() + .write(true) + .append(true) // This is needed to append to file + .open(VERIFIED) + .unwrap(); + write!(file, "{}\n", image_uri).unwrap(); + }, + 'q' => return true, + 'd' => { + let mut file = std::fs::OpenOptions::new() + .write(true) + .append(true) // This is needed to append to file + .open(REJECTED) + .unwrap(); + write!(file, "{}\n", image_uri).unwrap(); + }, + _ => return input_parse(image_uri), + }; + false +} \ No newline at end of file