biliapi/requests/
vote_info.rs

1//! 获取专栏投票信息
2use crate::requests::prelude::*;
3use chrono::{DateTime, Utc};
4
5/// 通过 vote id 获取专栏投票信息,需要登录才可以获取具体票数
6#[derive(Debug, Deserialize, Serialize, Clone)]
7pub struct VoteInfo {
8    pub vote_id: u64,
9
10    pub title: String,
11
12    pub choice_cnt: u64,
13    /// 大概是总票数
14    pub cnt: u64,
15
16    #[serde(with = "chrono::serde::ts_seconds", rename = "endtime")]
17    pub end_time: DateTime<Utc>,
18
19    pub options: Vec<VoteOption>,
20
21    #[serde(with = "chrono::serde::ts_seconds", rename = "starttime")]
22    pub start_time: DateTime<Utc>,
23}
24
25impl Request for VoteInfo {
26    // vote id
27    type Args = u64;
28    fn request(client: &Client, args: Self::Args) -> RequestResponse<Self> {
29        let r = client
30            .get("https://api.vc.bilibili.com/vote_svr/v1/vote_svr/vote_info")
31            .query(&[("vote_id", args)])
32            .send();
33
34        #[derive(Debug, Deserialize)]
35        struct Helper {
36            pub info: VoteInfo,
37        }
38
39        Box::pin(async move {
40            let helper: Helper = r.await?.bili_data().await?;
41            Ok(helper.info)
42        })
43    }
44}
45
46#[derive(Debug, Deserialize, Serialize, Clone)]
47pub struct VoteOption {
48    pub btn_str: String,
49    pub cnt: u64,
50    pub desc: String,
51    pub idx: u32,
52    pub title: String,
53}