ZJU-JWB scraper

Build status Coverage Status Crate version License: MIT Rust Docs

service

```rust,ignore

[async_trait]

pub trait JWService { type Err; async fn login(&self, stuid: &str, password: &str) -> Result; async fn getcourseinfo(&self, code: &str) -> Result; async fn getcourses( &self, stuid: &str, schoolyear: SchoolYear, semester: CourseSemester, cookie: &str, ) -> Result, Self::Err>; async fn getexams( &self, stuid: &str, schoolyear: SchoolYear, semester: ExamSemester, cookie: &str, ) -> Result, Self::Err>; async fn getscores(&self, stuid: &str, cookie: &str) -> Result, Self::Err>; async fn getmajorscores( &self, stuid: &str, cookie: &str, ) -> Result, Self::Err>; async fn gettotalcredit(&self, stu_id: &str, cookie: &str) -> Result; } ```

The JWService is implemented for all types which implements interfacer_http::HttpClient.

You can refer to src/test.rs for all use cases.

client

You can use this crate with client feature, like this:

toml zju-jw-scraper = { version = "0.2", features = ["client"] }

Then, you can use default client provided by interfacer-http-hyper:

```rust,norun use zjujw_scraper::{client::client, JWService};

[tokio::test]

async fn testlogin() -> Result<(), Box> { let service = client("http://jwbinfosys.zju.edu.cn".parse()?); let cookie = service.login("319000000", "test").await?; assert!(!cookie.isempty()); Ok(()) } ```

However, the default client can only handle requests on HTTP, if you want to use other protocol like HTTPS, you need other Connect.

As the example connector:

```rust,norun use hypertls::HttpsConnector; use zjujwscraper::{client::client_on, JWService};

[tokio::main]

async fn main() -> Result<(), Box> { let service = clienton("https://jw.zjuqsc.com".parse()?, HttpsConnector::new()?); let cookie = service.login("319000000", "test").await?; assert!(!cookie.isempty()); Ok(()) }

```

test

Run basic tests:

bash cargo test

To test this crate fully, create a config file test-settings.toml, and fill it referring to test-settings.toml.sample. Then run tests:

bash cargo test --all --all-features

As an alternative, you can configure tests using environment variables with prefix TEST_.

bash TEST_stu_id=3190000000 cargo test --all --all-features

Environment variables always have higher priority.