mastodon-async/examples/home_timeline.rs

46 lines
1.1 KiB
Rust
Raw Permalink Normal View History

2022-11-27 14:44:43 +00:00
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
mod register;
2022-12-23 15:09:33 +00:00
use futures_util::StreamExt;
use mastodon_async::Result;
2022-11-27 14:44:43 +00:00
#[cfg(feature = "toml")]
async fn run() -> Result<()> {
2022-12-23 15:09:33 +00:00
register::get_mastodon_data()
.await?
.get_home_timeline()
.await?
.items_iter()
.for_each(|status| async move {
print!(
"\ttoot from {}:\n{}",
status.account.display_name,
html2text::parse(status.content.as_bytes())
.render_plain(90)
.into_string()
)
})
.await;
2022-11-27 14:44:43 +00:00
Ok(())
}
#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}
#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}
2022-11-27 14:44:43 +00:00
#[cfg(not(feature = "toml"))]
fn main() {
println!(
"examples require the `toml` feature, run this command for this example:\n\ncargo run \
--example print_your_profile --features toml\n"
);
}