From 27baf0ab8005eed210a34d87a1c1f10b3f351d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Tue, 20 Jun 2023 16:02:12 +0100 Subject: [PATCH] add is_live check --- Cargo.lock | 5 +++-- Cargo.toml | 1 + src/live.rs | 21 +++++++++++++++++++++ src/main.rs | 15 ++++++++++----- templates/home.html.tera | 2 +- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/live.rs diff --git a/Cargo.lock b/Cargo.lock index e0c1600..67ba3e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2080,9 +2080,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a" dependencies = [ "itoa", "ryu", @@ -2158,6 +2158,7 @@ dependencies = [ "rocket", "rocket_dyn_templates", "serde", + "serde_json", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index d88284e..57ea2d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ serde = { version = "1.0", features = ["derive"] } rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] } listenbrainz = "0.7" chrono = "0.4.23" +serde_json = "1.0.97" diff --git a/src/live.rs b/src/live.rs new file mode 100644 index 0000000..4efb0d9 --- /dev/null +++ b/src/live.rs @@ -0,0 +1,21 @@ +use reqwest::Client; +use serde::Deserialize; + +use crate::Result; + +#[derive(Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct LiveStatus { + pub online: bool, + pub viewer_count: u32, +} + +pub async fn get_live_status(client: &Client) -> Result { + let endpoint = "https://weirdstar.stream/api/status"; + Ok(client + .get(endpoint) + .send() + .await? + .json::() + .await?) +} diff --git a/src/main.rs b/src/main.rs index ab65f8e..57d4973 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod error; +mod live; mod posts; mod scrobbles; mod skweets; @@ -17,27 +18,30 @@ type Result = std::result::Result; struct Clients { listenbrainz: listenbrainz::raw::Client, skinnyverse: mastodon_async::Mastodon, + reqwest: reqwest::Client, } #[macro_use] extern crate rocket; #[get("/")] -async fn home(clients: &State) -> Result