Read feeds from file
This commit is contained in:
parent
bce81ef67b
commit
17b85d11b2
32
src/main.rs
32
src/main.rs
@ -7,19 +7,45 @@ use feed_rs::{
|
|||||||
model::Feed,
|
model::Feed,
|
||||||
};
|
};
|
||||||
|
|
||||||
use reqwest::IntoUrl;
|
use reqwest::{
|
||||||
|
IntoUrl,
|
||||||
|
Url,
|
||||||
|
};
|
||||||
|
|
||||||
fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
|
fn fetch_feed(url: impl IntoUrl) -> Result<Feed> {
|
||||||
let content = reqwest::blocking::get(url)?.bytes()?;
|
let content = reqwest::blocking::get(url)?.bytes()?;
|
||||||
Ok(parse(&content[..])?)
|
Ok(parse(&content[..])?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_feed_file(path: &str) -> Result<Vec<Url>> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
|
||||||
|
for line in std::fs::read_to_string(path)?.lines() {
|
||||||
|
let line = line.trim().to_string();
|
||||||
|
if line == "" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if line.starts_with("#") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let url = Url::parse(&line)?;
|
||||||
|
println!("{}", url);
|
||||||
|
|
||||||
|
out.push(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
|
||||||
let mut feed_items = Vec::new();
|
let mut feed_items = Vec::new();
|
||||||
|
|
||||||
feed_items.extend(fetch_feed("https://www.youtube.com/feeds/videos.xml?channel_id=UC0intLFzLaudFG-xAvUEO-A")?.entries);
|
let feeds = read_feed_file("feeds.txt")?;
|
||||||
feed_items.extend(fetch_feed("https://feed.zugfunk-podcast.de/")?.entries);
|
|
||||||
|
for feed_url in feeds {
|
||||||
|
feed_items.extend(fetch_feed(feed_url)?.entries);
|
||||||
|
}
|
||||||
|
|
||||||
feed_items.sort_by(|a, b| a.published.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.published.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse());
|
feed_items.sort_by(|a, b| a.published.unwrap_or(chrono::DateTime::UNIX_EPOCH).cmp(&b.published.unwrap_or(chrono::DateTime::UNIX_EPOCH)).reverse());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user