diff options
author | Vika <vika@fireburn.ru> | 2023-07-01 20:33:37 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2023-07-09 01:42:47 +0300 |
commit | 9ce77c472bef59918d14b52af1332e454516e486 (patch) | |
tree | 90cf42e2821754a3a32be43474b1a06747a61a19 /kittybox-rs/src/bin/kittybox-mf2.rs | |
parent | d9e7fa9247925fc07f968efdcf831f3cb14539ef (diff) | |
download | kittybox-9ce77c472bef59918d14b52af1332e454516e486.tar.zst |
New debug utilities to test checking webmentions and parsing mf2
Diffstat (limited to 'kittybox-rs/src/bin/kittybox-mf2.rs')
-rw-r--r-- | kittybox-rs/src/bin/kittybox-mf2.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/kittybox-rs/src/bin/kittybox-mf2.rs b/kittybox-rs/src/bin/kittybox-mf2.rs new file mode 100644 index 0000000..4366cb8 --- /dev/null +++ b/kittybox-rs/src/bin/kittybox-mf2.rs @@ -0,0 +1,49 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[clap( + name = "kittybox-mf2", + author = "Vika <vika@fireburn.ru>", + version = env!("CARGO_PKG_VERSION"), + about = "Fetch HTML and turn it into MF2-JSON" +)] +struct Args { + #[clap(value_parser)] + url: url::Url, +} + +#[derive(thiserror::Error, Debug)] +enum Error { + #[error("http request error: {0}")] + Http(#[from] reqwest::Error), + #[error("microformats error: {0}")] + Microformats(#[from] microformats::Error), + #[error("json error: {0}")] + Json(#[from] serde_json::Error), + #[error("url parse error: {0}")] + UrlParse(#[from] url::ParseError), +} + +#[tokio::main] +async fn main() -> Result<(), Error> { + let args = Args::parse(); + + let http: reqwest::Client = { + #[allow(unused_mut)] + let mut builder = reqwest::Client::builder() + .user_agent(concat!( + env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION") + )); + + builder.build().unwrap() + }; + + let response = http.get(args.url.clone()).send().await?; + let text = response.text().await?; + + let mf2 = microformats::from_html(text.as_ref(), args.url)?; + + println!("{}", serde_json::to_string_pretty(&mf2)?); + + Ok(()) +} |