did the choosing thingy
This commit is contained in:
parent
3380cb8de4
commit
83dcaa8905
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
*.csv
|
|
@ -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"
|
|
@ -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]
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue