diff --git a/Cargo.lock b/Cargo.lock index d629dc7..0cc1499 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,14 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bot" +version = "0.1.0" +dependencies = [ + "affluences-api", + "tokio", +] + [[package]] name = "bumpalo" version = "3.12.2" @@ -201,6 +209,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.1" @@ -313,7 +330,7 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.1", "libc", "windows-sys 0.48.0", ] @@ -357,6 +374,16 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.17" @@ -402,6 +429,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + [[package]] name = "once_cell" version = "1.17.1" @@ -452,6 +489,29 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "windows-sys 0.45.0", +] + [[package]] name = "percent-encoding" version = "2.2.0" @@ -494,6 +554,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -569,6 +638,12 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "security-framework" version = "2.8.2" @@ -635,6 +710,15 @@ dependencies = [ "serde", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.8" @@ -644,6 +728,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + [[package]] name = "socket2" version = "0.4.9" @@ -673,7 +763,7 @@ checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.3.5", "rustix", "windows-sys 0.45.0", ] @@ -703,11 +793,26 @@ dependencies = [ "bytes", "libc", "mio", + "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", + "tokio-macros", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 463e8e1..e07b19a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,5 @@ members = [ "affluences-api", + "bot", ] diff --git a/affluences-api/API.md b/affluences-api/API.md new file mode 100644 index 0000000..24a739c --- /dev/null +++ b/affluences-api/API.md @@ -0,0 +1,26 @@ +curl -L 'https://api.affluences.com/app/v3/sites/ghent-university' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0' + +returnt lijst van alle bibliotheken op ugent, inclusief de uuids die dan nodig zijn om de specifieke requests te sturen naar die bib zijn stuff + +curl -L 'https://api.affluences.com/app/v3/timetables/4737e57a-ee05-4f7b-901a-7bb541eeb297?offset=0' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0' + +returnt de time table voor die bib + +https://reservation.affluences.com/api/sites/4737e57a-ee05-4f7b-901a-7bb541eeb297 + +Basisinformatie voor s5 bib + +https://reservation.affluences.com/api/resources/4737e57a-ee05-4f7b-901a-7bb541eeb297?type=1 + +returnt lijst van mogelijke lokalen voor s5 + +https://reservation.affluences.com/api/resources/4737e57a-ee05-4f7b-901a-7bb541eeb297/available?date=2023-05-11&type=1 + +returnt momenten die nog vrij zijn voor gegeven datum + +pretty sure da die type 1 slaat op da et een bib is + +https://api.affluences.com/app/v3/sites +body: {"selected_categories":[1],"page":0,"search_query":"university of ghent"} + +zoek op alle mogelijke bibs, met een search query diff --git a/affluences-api/src/lib.rs b/affluences-api/src/lib.rs index 7d12d9a..c3d6a06 100644 --- a/affluences-api/src/lib.rs +++ b/affluences-api/src/lib.rs @@ -1,14 +1,22 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +mod models; + +use models::Resource; + +const USER_AGENT: &str = "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"; + +pub struct AffluencesClient { + client: reqwest::Client, } -#[cfg(test)] -mod tests { - use super::*; +impl AffluencesClient { + pub fn new() -> Self { + Self { + client: reqwest::Client::builder() + .user_agent(USER_AGENT).build().unwrap(), + } + } - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + pub async fn available(&mut self) -> reqwest::Result> { + self.client.get("https://reservation.affluences.com/api/resources/026b8caa-d310-464f-b714-4c21a2cf98ea/available?date=2023-05-11&type=1").send().await?.json::>().await } } diff --git a/affluences-api/src/models.rs b/affluences-api/src/models.rs new file mode 100644 index 0000000..c90b530 --- /dev/null +++ b/affluences-api/src/models.rs @@ -0,0 +1,40 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Debug)] +pub struct Hour { + pub hour: String, + pub state: u32, + // reservations + pub granularity: u32, + pub person_count: u32, + pub places_available: u32, + pub places_bookable: u32, +} + +#[derive(Deserialize, Debug)] +pub struct Resource { + pub resource_id: u32, + pub resource_name: String, + pub resource_type: u32, + pub granularity: u32, + pub time_slot_count: u32, + pub static_time_slot: bool, + // reservations_by_timeslot + pub note_available: bool, + pub note_required: bool, + pub note_description: String, + pub description: String, + pub capacity: u32, + pub site_timezone: String, + pub user_name_required: bool, + pub user_phone_required: bool, + pub user_name_available: bool, + pub user_phone_available: bool, + // time_before_reservations_closed + // min_places_per_reservation + // max_places_per_reservation + pub image_url: Option, + // services + pub slots_state: u32, + pub hours: Vec, +} diff --git a/bot/Cargo.toml b/bot/Cargo.toml new file mode 100644 index 0000000..b4ba5ea --- /dev/null +++ b/bot/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "bot" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +affluences-api = { path = "../affluences-api" } +tokio = { version = "1.28.1", features = ["full"] } diff --git a/bot/src/main.rs b/bot/src/main.rs new file mode 100644 index 0000000..f9e545c --- /dev/null +++ b/bot/src/main.rs @@ -0,0 +1,8 @@ +use affluences_api::AffluencesClient; + +#[tokio::main] +async fn main() { + let mut client = AffluencesClient::new(); + let res = client.available().await.unwrap(); + println!("{:?}", res); +} diff --git a/main.rs b/main.rs new file mode 100644 index 0000000..a58a09d --- /dev/null +++ b/main.rs @@ -0,0 +1,8 @@ +use reqwest; +type Response = Vec; + +fn main() { + let res = reqwest::blocking::get("https://reservation.affluences.com/api/resources/026b8caa-d310-464f-b714-4c21a2cf98ea/available?date=2023-05-11&type=1").unwrap().json::().unwrap(); + println!("{:?}", res); +} +