From 5859359f124243c9f38a9f59be4504b2df786456 Mon Sep 17 00:00:00 2001 From: Bizcochito Date: Wed, 15 Feb 2023 19:00:48 +0100 Subject: [PATCH] now it checks for colisions --- src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3843dd0..46699fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) { 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::(); + let image_set2 = std::fs::read(VERIFIED).expect("File not found").iter().map(|c| *c as char).collect::(); + let image_set3 = std::fs::read(REJECTED).expect("File not found").iter().map(|c| *c as char).collect::(); + + let image_set = image_set1.lines().chain(image_set2.lines()).chain(image_set3.lines()).collect::>(); + + 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) { .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(); + } } }