added dates, clippy fixes, sync date improvement

This commit is contained in:
2023-11-14 19:09:21 +01:00
parent ea754b6f3e
commit 91eeb29b06
6 changed files with 49 additions and 8 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
}
})
.configure(views::views_factory);
return app;
app
})
.bind("127.0.0.1:8001")?
.run()
+26 -4
View File
@@ -12,11 +12,34 @@ use crate::{
},
};
use actix_web::{web, HttpRequest, HttpResponse, Responder};
use chrono::{Local, NaiveDateTime};
use chrono::{DateTime, Local, NaiveDateTime};
use dateparser::parse;
use diesel::prelude::*;
use rss::Item;
use scraper::{Html, Selector};
fn get_date(date_str: &str) -> Result<NaiveDateTime, chrono::ParseError> {
// let format_string = "%a, %d %b %Y %H:%M:%S %z";
let format_string = "%Y-%m-%dT%H:%M:%S%Z";
let result = parse(date_str).unwrap();
log::info!("Date: {:?}", result);
match NaiveDateTime::parse_from_str(&result.to_string(), format_string) {
Ok(r) => Ok(r),
Err(_) => {
let datetime = DateTime::parse_from_rfc2822(date_str);
match datetime {
Ok(r) => NaiveDateTime::parse_from_str(&r.to_rfc3339(), format_string),
Err(_) => match DateTime::parse_from_rfc2822(date_str) {
Ok(r) => NaiveDateTime::parse_from_str(&r.to_rfc3339(), format_string),
Err(e) => Err(e),
},
}
}
}
}
fn create_feed_item(item: Item, feed: &Feed, connection: &mut PgConnection) {
let item_title = item.title.clone().unwrap();
log::info!("Create feed item: {}", item_title);
@@ -56,8 +79,7 @@ fn create_feed_item(item: Item, feed: &Feed, connection: &mut PgConnection) {
log::info!("{:?}", item.pub_date());
let mut time: NaiveDateTime = Local::now().naive_local();
if item.pub_date().is_some() {
let format_string = "%a, %d %b %Y %H:%M:%S %z";
time = match NaiveDateTime::parse_from_str(item.pub_date().unwrap(), format_string) {
time = match get_date(item.pub_date().unwrap()) {
Ok(date) => date,
Err(err) => {
log::error!("could not unwrap pub date: {}", err);
@@ -78,7 +100,7 @@ fn create_feed_item(item: Item, feed: &Feed, connection: &mut PgConnection) {
log::info!("Insert Result: {:?}", insert_result);
} else {
log::info!("Item {} already exists.", feed.title);
log::info!("Item {} already exists.", item_title);
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
pub async fn logout() -> String {
format!("logout view")
"logout view".to_string()
}
+1 -2
View File
@@ -8,10 +8,9 @@ impl Path {
match self.backend {
true => {
let path: String = self.prefix.to_owned() + &following_path;
return String::from("/api/v1") + &path;
String::from("/api/v1") + &path
}
false => self.prefix.to_owned() + &following_path,
}
}
}