Crate aerostream
source ·Expand description
Aerostream
Aerostream is Bluesky client using EventStream.
use std::{
io::{stdout, Write},
time::Duration,
};
use aerostream::Client;
use anyhow::Result;
use chrono::Local;
fn main() -> Result<()> {
env_logger::init();
let mut client = Client::default();
client.set_timeout(5);
client.connect_ws()?;
loop {
for (filter, event) in client.next_event_filtered_all()?.iter() {
let Some(commit) = event.as_commit() else {
continue;
};
let posts = commit.get_post_text();
if posts.is_empty() {
continue;
}
let text = posts.join(" ").replace("\n", " ");
let time = commit.time.with_timezone(&Local).format("%m/%d %H:%M");
let handle = match client.get_repo(&commit.repo) {
Ok(r) => r.handle.clone(),
_ => String::from("UNKNOWN"),
};
let blobs = commit
.blobs
.iter()
.map(|b| b.to_string())
.collect::<Vec<_>>();
print!("{} : {} : {} : {}", filter, time, handle, text);
if !commit.blobs.is_empty() {
println!(" : {}", blobs.join(","));
} else {
println!("");
}
stdout().flush().ok();
}
std::thread::sleep(Duration::from_millis(10));
}
}Re-exports
pub use client::Client;pub use client::Repo;pub use event::Blob;pub use event::Blocks;pub use event::Commit;pub use event::Event;pub use event::Handle;pub use event::Header;pub use event::Info;pub use event::Migrate;pub use event::Payload;pub use event::RepoOp;pub use event::Tombstone;pub use filter::Filter;pub use filter::Filters;pub use filter::Keywords;pub use filter::Subscribes;
Modules
- HTTP and WebSocket clients to connect to Bluesky
- Event to be received via EventStream
- Filter to return only matched events from EventStream