Fetch basic data from lemmy.ml

This commit is contained in:
Felix Ableitner 2021-03-09 19:08:42 +01:00
parent 5f871dcc96
commit 21be5c58ee
6 changed files with 1301 additions and 3 deletions

1228
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,3 +5,9 @@ authors = ["Felix Ableitner"]
edition = "2018"
[dependencies]
reqwest = { version = "0.10.10", features = ["json"] }
url = "2.2.1"
serde = { version = "1.0.123", features = ["derive"] }
anyhow = "1.0.38"
tokio = { version = "0.2.25", features = ["full"] }
futures = "0.3.13"

View file

@ -0,0 +1,14 @@
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct GetSiteResponse {
pub online: usize,
pub federated_instances: Option<FederatedInstances>,
}
#[derive(Deserialize, Debug)]
pub struct FederatedInstances {
pub linked: Vec<String>,
pub allowed: Option<Vec<String>>,
pub blocked: Option<Vec<String>>,
}

2
src/lib.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod node_info;
pub mod federated_instances;

View file

@ -1,3 +1,18 @@
fn main() {
println!("Hello, world!");
use anyhow::Error;
use url::Url;
use lemmy_stats_crawler::node_info::NodeInfo;
use lemmy_stats_crawler::federated_instances::GetSiteResponse;
#[tokio::main]
pub async fn main() -> Result<(), Error> {
let url = Url::parse("https://lemmy.ml/nodeinfo/2.0.json")?;
let node_info: NodeInfo = reqwest::get(url).await?.json().await?;
dbg!(node_info);
let url = Url::parse("https://lemmy.ml/api/v2/site")?;
let site_info: GetSiteResponse = reqwest::get(url).await?.json().await?;
dbg!(site_info);
Ok(())
}

33
src/node_info.rs Normal file
View file

@ -0,0 +1,33 @@
use serde::Deserialize;
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo {
pub version: String,
pub software: NodeInfoSoftware,
pub protocols: Vec<String>,
pub usage: NodeInfoUsage,
pub open_registrations: bool,
}
#[derive(Deserialize, Debug)]
pub struct NodeInfoSoftware {
pub name: String,
pub version: String,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfoUsage {
pub users: NodeInfoUsers,
pub local_posts: i64,
pub local_comments: i64,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfoUsers {
pub total: i64,
pub active_halfyear: i64,
pub active_month: i64,
}