1
0
mirror of https://gitlab.com/Anson-Projects/zine.git synced 2025-07-27 08:41:25 +00:00

Clean up code

This commit is contained in:
2024-12-10 21:32:01 -07:00
parent 3323b8a989
commit b54d1d339d
5 changed files with 164 additions and 192 deletions

View File

@@ -17,44 +17,42 @@ use rayon::prelude::*;
fn main() -> Result<(), Box<dyn Error>> {
simple_logger::init_with_level(log::Level::Info).unwrap();
let main_post_count = 24;
let archive_size = 100;
let all_posts = utilities::read_feed("feeds.txt");
let mut all_posts = utilities::read_feed("feeds.txt");
// Give featured a small boost in points
let featured = utilities::read_feed("featured_feeds.txt")
.iter_mut()
.map(|post| {
post.score += post.score / 2;
post.clone()
})
.collect::<Vec<_>>();
all_posts.extend(featured);
let mut posts = all_posts.clone();
posts.retain(|post| post.score.is_positive());
posts.par_iter_mut().for_each(utilities::validate);
posts.sort();
// Move the post with an image_url to the head of the list which is the featured post
if let Some(pos) = posts.iter().position(|post| post.image_url.is_some()) {
let post_with_image = posts.remove(pos);
posts.insert(0, post_with_image);
}
// Keep only the first occurence of each main_url
{
let mut seen_urls = HashSet::new();
posts.retain(|post| seen_urls.insert(post.main_url.clone()));
}
let mut featured = utilities::read_feed("featured_feeds.txt");
// Give featured a small boost in points
featured = featured
.iter_mut()
.map(|post| {
post.score = (post.score as f64 * 1.5) as i64;
post.clone()
})
.collect::<Vec<_>>();
posts.extend(featured);
posts.par_iter_mut().for_each(utilities::find_image);
posts.par_iter_mut().for_each(utilities::validate);
posts.sort();
// Move the post with an image_url to the head of the list
if let Some(pos) = posts.iter().position(|post| post.image_url.is_some()) {
let post_with_image = posts.remove(pos);
posts.insert(0, post_with_image);
}
utilities::retain_most_recent_based_on_main_url(&mut posts);
posts.truncate(24);
posts.truncate(main_post_count);
let mut old_posts = all_posts;
@@ -62,7 +60,6 @@ fn main() -> Result<(), Box<dyn Error>> {
old_posts.shuffle(&mut thread_rng());
let mut archive_posts: Vec<utilities::Post> = Vec::new();
let archive_size = 100;
while (archive_posts.len() < archive_size) && (old_posts.len() > 50) {
let iter_size = archive_size - archive_posts.len();