added dates, clippy fixes, sync date improvement
parent
ea754b6f3e
commit
91eeb29b06
|
@ -263,6 +263,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.75"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atom_syndication"
|
name = "atom_syndication"
|
||||||
version = "0.12.2"
|
version = "0.12.2"
|
||||||
|
@ -575,6 +581,18 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dateparser"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18e537db44ee4822af930a9a2c9eedfcde9d47e01c6731fbf34ea01b5a7ccf7d"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"chrono",
|
||||||
|
"lazy_static",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -1818,6 +1836,7 @@ dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"dateparser",
|
||||||
"diesel",
|
"diesel",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
|
@ -27,6 +27,7 @@ env_logger = "0.9.3"
|
||||||
scraper = "0.14.0"
|
scraper = "0.14.0"
|
||||||
actix-cors = "0.6.4"
|
actix-cors = "0.6.4"
|
||||||
chrono = { version = "0.4.31", features = ["serde"] }
|
chrono = { version = "0.4.31", features = ["serde"] }
|
||||||
|
dateparser = "0.2.0"
|
||||||
|
|
||||||
[dependencies.serde_json]
|
[dependencies.serde_json]
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
|
|
|
@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.configure(views::views_factory);
|
.configure(views::views_factory);
|
||||||
return app;
|
app
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8001")?
|
.bind("127.0.0.1:8001")?
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -12,11 +12,34 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||||
use chrono::{Local, NaiveDateTime};
|
use chrono::{DateTime, Local, NaiveDateTime};
|
||||||
|
use dateparser::parse;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use rss::Item;
|
use rss::Item;
|
||||||
use scraper::{Html, Selector};
|
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) {
|
fn create_feed_item(item: Item, feed: &Feed, connection: &mut PgConnection) {
|
||||||
let item_title = item.title.clone().unwrap();
|
let item_title = item.title.clone().unwrap();
|
||||||
log::info!("Create feed item: {}", item_title);
|
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());
|
log::info!("{:?}", item.pub_date());
|
||||||
let mut time: NaiveDateTime = Local::now().naive_local();
|
let mut time: NaiveDateTime = Local::now().naive_local();
|
||||||
if item.pub_date().is_some() {
|
if item.pub_date().is_some() {
|
||||||
let format_string = "%a, %d %b %Y %H:%M:%S %z";
|
time = match get_date(item.pub_date().unwrap()) {
|
||||||
time = match NaiveDateTime::parse_from_str(item.pub_date().unwrap(), format_string) {
|
|
||||||
Ok(date) => date,
|
Ok(date) => date,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("could not unwrap pub date: {}", 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);
|
log::info!("Insert Result: {:?}", insert_result);
|
||||||
} else {
|
} else {
|
||||||
log::info!("Item {} already exists.", feed.title);
|
log::info!("Item {} already exists.", item_title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
pub async fn logout() -> String {
|
pub async fn logout() -> String {
|
||||||
format!("logout view")
|
"logout view".to_string()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,9 @@ impl Path {
|
||||||
match self.backend {
|
match self.backend {
|
||||||
true => {
|
true => {
|
||||||
let path: String = self.prefix.to_owned() + &following_path;
|
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,
|
false => self.prefix.to_owned() + &following_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue