Basic fetch channel
This commit is contained in:
parent
38d1cbbd50
commit
e1cb00f0b1
4 changed files with 2156 additions and 0 deletions
2120
koucha/Cargo.lock
generated
2120
koucha/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,3 +4,7 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8.8"
|
||||
reqwest = "0.13.1"
|
||||
rss = "2.0.12"
|
||||
tokio = { version = "1.49.0", features = ["full"] }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
use std::error::Error;
|
||||
use reqwest::Client;
|
||||
use koucha::fetch_channel;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let client = Client::new();
|
||||
let _channel = fetch_channel(&client, "https://lorem-rss.herokuapp.com/feed?unit=year").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
use std::error::Error;
|
||||
use reqwest::{
|
||||
IntoUrl,
|
||||
Client,
|
||||
};
|
||||
use rss::Channel as RawChannel;
|
||||
|
||||
pub struct Channel {
|
||||
pub channel: rss::Channel,
|
||||
}
|
||||
|
||||
pub async fn fetch_channel<T: IntoUrl>(
|
||||
client: &Client, url: T) -> Result<Channel, Box<dyn Error>> {
|
||||
let content = client.get(url)
|
||||
.send().await?
|
||||
.bytes().await?;
|
||||
|
||||
let raw_channel = RawChannel::read_from(&content[..])?;
|
||||
println!("{}", raw_channel.title);
|
||||
Ok(Channel { channel: raw_channel })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue