spread out posts within the same minute
This commit is contained in:
parent
0a2c67f47c
commit
bac2311bc7
19
src/main.rs
19
src/main.rs
|
@ -5,7 +5,9 @@ use actix_web::{
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
use time::{format_description::well_known::Rfc3339, OffsetDateTime, PrimitiveDateTime, UtcOffset};
|
use time::{
|
||||||
|
format_description::well_known::Rfc3339, Duration, OffsetDateTime, PrimitiveDateTime, UtcOffset,
|
||||||
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref FIRST_TEXT_SEL: Selector = Selector::parse("#delform > blockquote").unwrap();
|
static ref FIRST_TEXT_SEL: Selector = Selector::parse("#delform > blockquote").unwrap();
|
||||||
|
@ -106,6 +108,8 @@ async fn get_posts(thread_id: &str) -> Option<Vec<Post>> {
|
||||||
.and_then(extract_time)
|
.and_then(extract_time)
|
||||||
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
||||||
|
|
||||||
|
let mut last_time = first_time;
|
||||||
|
|
||||||
let mut posts = vec![Post {
|
let mut posts = vec![Post {
|
||||||
text: first_text,
|
text: first_text,
|
||||||
image: first_image,
|
image: first_image,
|
||||||
|
@ -137,11 +141,22 @@ async fn get_posts(thread_id: &str) -> Option<Vec<Post>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let time = element
|
|
||||||
|
let mut time = element
|
||||||
.select(&TIME_SEL)
|
.select(&TIME_SEL)
|
||||||
.next()
|
.next()
|
||||||
.and_then(extract_time)
|
.and_then(extract_time)
|
||||||
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
.unwrap_or(OffsetDateTime::UNIX_EPOCH);
|
||||||
|
// Spread out posts within the same minute so they'll be sorted properly
|
||||||
|
if last_time - (last_time.second() * Duration::SECOND) == time {
|
||||||
|
if last_time.second() < 59 {
|
||||||
|
last_time += Duration::SECOND;
|
||||||
|
}
|
||||||
|
time = last_time;
|
||||||
|
} else {
|
||||||
|
last_time = time;
|
||||||
|
}
|
||||||
|
|
||||||
posts.push(Post {
|
posts.push(Post {
|
||||||
text,
|
text,
|
||||||
image,
|
image,
|
||||||
|
|
Loading…
Reference in a new issue