Update
This commit is contained in:
parent
f38d80d030
commit
ff24aa7a2f
1 changed files with 76 additions and 3 deletions
79
src/lib.rs
79
src/lib.rs
|
@ -285,7 +285,7 @@ struct ApiTeachersResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ApiReportStudent {
|
pub struct ApiReportUser {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(rename = "longName")]
|
#[serde(rename = "longName")]
|
||||||
pub long_name: String,
|
pub long_name: String,
|
||||||
|
@ -746,7 +746,7 @@ impl Client {
|
||||||
Ok(resp.data.elements)
|
Ok(resp.data.elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn student_reports(&self, class_id: i32) -> Result<Vec<ApiReportStudent>> {
|
pub async fn student_reports(&self, class_id: i32) -> Result<Vec<ApiReportUser>> {
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Data {
|
struct Data {
|
||||||
finished: bool,
|
finished: bool,
|
||||||
|
@ -816,7 +816,80 @@ impl Client {
|
||||||
.from_reader(records.as_bytes());
|
.from_reader(records.as_bytes());
|
||||||
|
|
||||||
Ok(reader
|
Ok(reader
|
||||||
.deserialize::<ApiReportStudent>()
|
.deserialize::<ApiReportUser>()
|
||||||
|
.collect::<Result<Vec<_>, _>>()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn teacher_reports(&self, class_id: i32) -> Result<Vec<ApiReportUser>> {
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct Data {
|
||||||
|
finished: bool,
|
||||||
|
error: bool,
|
||||||
|
#[serde(rename = "messageId")]
|
||||||
|
message_id: i32,
|
||||||
|
#[serde(rename = "reportParams")]
|
||||||
|
report_params: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct Response {
|
||||||
|
data: Data,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut url = self.webuntis_url.join("reports.do")?;
|
||||||
|
url.query_pairs_mut()
|
||||||
|
.append_pair("name", "Teacher")
|
||||||
|
.append_pair("format", "csv")
|
||||||
|
.append_pair("elementsForDate", "true");
|
||||||
|
let resp: Response = reqwest::Client::new()
|
||||||
|
.get(url)
|
||||||
|
.header(reqwest::header::USER_AGENT, &self.user_agent)
|
||||||
|
.header(reqwest::header::ACCEPT, "application/json")
|
||||||
|
.header(
|
||||||
|
reqwest::header::COOKIE,
|
||||||
|
self.session.as_ref().context("Not logged in")?,
|
||||||
|
)
|
||||||
|
.header(
|
||||||
|
reqwest::header::AUTHORIZATION,
|
||||||
|
Client::construct_bearer(&self.authorization.as_ref().context("Not logged in")?),
|
||||||
|
)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.json()
|
||||||
|
.await?;
|
||||||
|
if resp.data.error {
|
||||||
|
bail!("Error generating report");
|
||||||
|
} else if !resp.data.finished {
|
||||||
|
bail!("Report not finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut records_url = self.webuntis_url.join("reports.do")?;
|
||||||
|
records_url.set_query(Some(&resp.data.report_params));
|
||||||
|
records_url
|
||||||
|
.query_pairs_mut()
|
||||||
|
.append_pair("msgId", &resp.data.message_id.to_string());
|
||||||
|
let records = reqwest::Client::new()
|
||||||
|
.get(records_url)
|
||||||
|
.header(reqwest::header::USER_AGENT, &self.user_agent)
|
||||||
|
.header(reqwest::header::ACCEPT, "text/csv")
|
||||||
|
.header(
|
||||||
|
reqwest::header::COOKIE,
|
||||||
|
self.session.as_ref().context("Not logged in")?,
|
||||||
|
)
|
||||||
|
.header(
|
||||||
|
reqwest::header::AUTHORIZATION,
|
||||||
|
Client::construct_bearer(&self.authorization.as_ref().context("Not logged in")?),
|
||||||
|
)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
let mut reader = csv::ReaderBuilder::new()
|
||||||
|
.delimiter(b'\t')
|
||||||
|
.from_reader(records.as_bytes());
|
||||||
|
|
||||||
|
Ok(reader
|
||||||
|
.deserialize::<ApiReportUser>()
|
||||||
.collect::<Result<Vec<_>, _>>()?)
|
.collect::<Result<Vec<_>, _>>()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue