Compare commits
No commits in common. "d0ac11ea898b27999ecd2dd6228c2132a69d63b4" and "cd590b73fefbe259843d79d3586210fd9a0c36e0" have entirely different histories.
d0ac11ea89
...
cd590b73fe
@ -56,7 +56,7 @@ pub async fn fetch_and_parse_feed(uri: &str) -> Result<Feed, Box<dyn Error>> {
|
||||
let http_client = reqwest::Client::builder().default_headers(headers).build()?;
|
||||
let response = http_client.get(uri).send().await?.text().await?;
|
||||
|
||||
info!("Got response, parsing feed from {}", uri);
|
||||
info!("Got response, parsing feed");
|
||||
let feed = parser::parse(response.as_bytes())?;
|
||||
|
||||
let feed_title = match feed.title.clone() {
|
||||
@ -82,11 +82,7 @@ pub fn format_entry(feed: Feed, entry: model::Entry) -> Result<Entry, Box<dyn Er
|
||||
Some(t) => t.content,
|
||||
None => String::from("Untitled")
|
||||
},
|
||||
link: if entry.links.len() > 0 {
|
||||
entry.links[0].href.clone()
|
||||
} else {
|
||||
String::from("#")
|
||||
},
|
||||
link: entry.links[0].href.clone(),
|
||||
ts: match entry.updated {
|
||||
Some(d) => d,
|
||||
None => entry.published.unwrap_or(Utc::now())
|
||||
|
24
src/main.rs
24
src/main.rs
@ -39,7 +39,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use std::{ sync::Arc, cmp::max };
|
||||
use tracing::{ info, debug, error };
|
||||
use tracing::{ info, debug };
|
||||
use chrono::DateTime;
|
||||
|
||||
#[tokio::main]
|
||||
@ -51,7 +51,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
// This message passing channel is used for sending messages to the matrix module,
|
||||
// it holds a tuple with an HTML message and a list of rooms to post to
|
||||
let (bcast_tx, bcast_rx) = broadcast::channel(1024);
|
||||
let (bcast_tx, bcast_rx) = broadcast::channel(16);
|
||||
|
||||
let state_db = FeedReaderStateDb::new("state.yaml").await
|
||||
.expect("Failed to initialize feed reader state db");
|
||||
@ -63,24 +63,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
tokio::spawn(async move {
|
||||
|
||||
loop {
|
||||
let feed: Option<_> = match fetch_and_parse_feed(&feed_config.url).await {
|
||||
Ok(f) => Some(f),
|
||||
Err(e) => {
|
||||
error!("Failed to parse feed {}: {:?}",
|
||||
feed_config.url,
|
||||
e
|
||||
);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
let feed = if feed.is_none() {
|
||||
info!("Sleeping for {} seconds before refreshing this feed", feed_config.delay);
|
||||
sleep(Duration::from_secs(feed_config.delay)).await;
|
||||
continue;
|
||||
} else {
|
||||
feed.unwrap()
|
||||
};
|
||||
let feed = fetch_and_parse_feed(&feed_config.url).await
|
||||
.expect("Failed to parse feed");
|
||||
|
||||
let rooms = feed_config.rooms.clone();
|
||||
|
||||
|
@ -32,8 +32,6 @@ use tokio::{
|
||||
sync::broadcast
|
||||
};
|
||||
|
||||
use tracing::info;
|
||||
|
||||
async fn on_stripped_state_member(
|
||||
room_member: StrippedRoomMemberEvent,
|
||||
client: Client,
|
||||
@ -99,24 +97,18 @@ pub async fn login_and_sync<T: Clone>(
|
||||
loop {
|
||||
tokio::select! {
|
||||
Ok(_) = client.sync(settings.clone()) => return Ok(()),
|
||||
recv = rx.recv() => match recv {
|
||||
Ok((msg, rooms)) => {
|
||||
Ok((msg, rooms)) = rx.recv() => {
|
||||
|
||||
let msg = &msg.clone();
|
||||
for r in rooms {
|
||||
info!("Joining room {}", r);
|
||||
let room = client.join_room_by_id(<&RoomId>::try_from(r.as_str())
|
||||
.expect("invalid room ID")
|
||||
).await.expect(format!("Failed to join room {}", r).as_str());
|
||||
|
||||
info!("Posting to room {}", r);
|
||||
room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await
|
||||
.expect("Failed to send matrix event");
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
panic!("Broadcast channel is lagging: {e:?}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user