did the choosing thingy

This commit is contained in:
Bizcochito 2023-02-15 17:43:38 +01:00
parent 3380cb8de4
commit 83dcaa8905
4 changed files with 69 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
*.csv

7
Cargo.lock generated Normal file
View File

@ -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"

8
Cargo.toml Normal file
View File

@ -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]

52
src/main.rs Normal file
View File

@ -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::<String>())).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
}