get feed lists and return feeds

This commit is contained in:
death916 2026-03-24 04:34:32 -07:00
parent 7b00e23a08
commit 6d4201c378
4 changed files with 51 additions and 26 deletions

14
rustclock/Cargo.lock generated
View file

@ -4319,11 +4319,25 @@ dependencies = [
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.61.2",
]
[[package]]
name = "tokio-macros"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-rustls"
version = "0.26.4"

View file

@ -10,5 +10,5 @@ reqwest = "0.13.2"
rss = "2.0.12"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
tokio = "1.50.0"
tokio = { version = "1.50.0", features = ["full"] }
ureq = "3.2.0"

View file

@ -2,25 +2,17 @@ use rss::Channel;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::str::FromStr;
use ureq::http::Response;
pub fn get_news() {
pub async fn get_news() -> Vec<Channel> {
let feeds = File::open("../feeds.txt");
let mut feed_vec = Vec::new();
let mut news = Vec::new();
match feeds {
Ok(file) => {
let reader = BufReader::new(file);
let channel = Channel::read_from(reader);
if let Ok(channel) = channel {
println!("Title: {}", channel.title());
println!("Link: {}", channel.link());
println!("Description: {}", channel.description());
} else {
eprintln!("Error parsing feed: {}", reader);
}
for line in reader.lines() {
if let Ok(feed) = line {
dbg!(&feed);
feed_vec.push(feed);
}
}
@ -31,20 +23,39 @@ pub fn get_news() {
}
for feed in feed_vec.iter() {
let content = feed.as_str();
dbg!(content);
let channel = Channel::from_str(content);
if let Ok(channel) = channel {
println!("Title: {}", channel.title());
println!("Link: {}", channel.link());
println!("Description: {}", channel.description());
} else {
eprintln!("Error parsing feed: {}", content);
let feed_url = feed.as_str();
let content = reqwest::get(feed_url).await;
match content {
Ok(contents) => {
let contents = contents.bytes().await;
if let Ok(response) = contents {
let channel = Channel::read_from(&response[..]);
// dbg!(&channel);
match channel {
Ok(feed) => {
dbg!("Title: {}", feed.title());
dbg!("Link: {}", feed.link());
news.push(feed);
}
Err(e) => {
eprintln!("Error parsing feed: {},{}", feed_url, e);
}
}
}
}
Err(e) => {
eprintln!("Error fetching feed: {},{}", feed_url, e);
continue;
}
}
}
news
}
#[test]
fn test() {
get_news();
#[tokio::test]
async fn test() {
let news = get_news().await;
assert!(news.len() > 0);
}

View file

@ -85,9 +85,9 @@ pub fn render_mlb_pane<'a>(
container(
column![
row![
image(team1_logo.clone()).width(15).height(15),
image(team1_logo.clone()).width(30).height(30),
text(&game.team1).size(20).width(Fill),
image(team2_logo.clone()).width(15).height(15),
image(team2_logo.clone()).width(30).height(30),
text(&game.team2).size(20).width(Fill),
],
row![