52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
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
|
|
} |