now it checks for colisions

This commit is contained in:
Bizcochito 2023-02-15 19:00:48 +01:00
parent d0e3e9e959
commit 5859359f12
1 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,6 @@
use std::{process::Command, io::{BufRead, Write}};
use gelbooru_api::{Client, posts};
use std::collections::HashSet;
const LEGEND: &str = "[q]uit, [d]elete, [a]ccept";
const PENDING: &str = "./pending.csv";
@ -18,10 +19,18 @@ async fn main(){
async fn fetch_mode(tags: Vec<String>) {
let client = Client::public();
let posts = dbg!(posts()
.tags(&tags)
.send(&client)
.await.unwrap());
let posts = posts()
.random(true)
.tags(&tags)
.send(&client);
let image_set1 = std::fs::read(PENDING).expect("File not found").iter().map(|c| *c as char).collect::<String>();
let image_set2 = std::fs::read(VERIFIED).expect("File not found").iter().map(|c| *c as char).collect::<String>();
let image_set3 = std::fs::read(REJECTED).expect("File not found").iter().map(|c| *c as char).collect::<String>();
let image_set = image_set1.lines().chain(image_set2.lines()).chain(image_set3.lines()).collect::<HashSet<_>>();
let posts = posts.await.unwrap();
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(true) // This is needed to append to file
@ -29,7 +38,10 @@ async fn fetch_mode(tags: Vec<String>) {
.unwrap();
for post in posts.posts {
write!(file, "{}\n", post.image_url()).unwrap();
let imgurl = post.image_url();
if !image_set.contains(imgurl){
write!(file, "{}\n", imgurl).unwrap();
}
}
}