mkdir src/sites/<<TARGET SITE>>
touch src/sites/<<TARGET SITE>>/mod.rs
touch src/sites/<<TARGET SITE>>/tests.rs
use crate::sites::{Category, Html, Text, Site, WebArticle};
use chrono::DateTime;
use feed_parser::parsers;
pub struct Gigazin {}
#[cfg(test)]
mod tests;
impl Site for Gigazin {
async fn get_articles(&self) -> Result<Vec<WebArticle>, String> {
let body = reqwest::get("https://gigazine.net/news/rss_2.0/")
.await
.unwrap()
.text()
.await
.unwrap();
let feeds = if let Ok(r) = parsers::rss2::parse(&body) {
r
} else {
return Err("Failed to parse RSS".to_string());
};
let mut articles = Vec::new();
for feed in feeds {
articles.push(WebArticle {
site: self.name(),
title: feed.title,
url: feed.link,
text: feed.description.unwrap_or("".to_string()),
timestamp: DateTime::parse_from_rfc2822(&feed.publish_date.unwrap())
.unwrap()
.into(),
});
}
return articles;
}
}
use super::*;
#[test]
fn test_codezin() {
let site = Gigazin {};
let articles = site.get_articles().await;
assert!(articles.len() > 0);
}
use chrono::{DateTime, Local};
use futures::Future;
mod codezin;
mod gigazin;
mod stockmarknews;
mod stockmarktechblog;
mod <<TARGET SITE>>
cargo test