Pull the AoC leaderboard API
This commit is contained in:
parent
a014b25947
commit
576df264f9
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
name = "challenge"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = { version = "0.11", features = [ "cookies" ] }
|
||||||
|
tokio = { version = "1.22", features = [ "full" ] }
|
|
@ -0,0 +1,34 @@
|
||||||
|
use reqwest;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let session_cookie = std::env::vars()
|
||||||
|
.find_map(|(key, value)| {
|
||||||
|
if key == "SESSION_COOKIE" {
|
||||||
|
Some(value)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let jar = reqwest::cookie::Jar::default();
|
||||||
|
let url = "https://adventofcode.com/".parse::<reqwest::Url>().unwrap();
|
||||||
|
jar.add_cookie_str(&format!("session={}", session_cookie), &url);
|
||||||
|
|
||||||
|
let client = reqwest::ClientBuilder::new()
|
||||||
|
.cookie_store(true)
|
||||||
|
.cookie_provider(std::sync::Arc::new(jar))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let board = client
|
||||||
|
.get("https://adventofcode.com/2021/leaderboard/private/view/680754.json")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.text()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
println!("resulting text: {:?}", board);
|
||||||
|
}
|
Loading…
Reference in New Issue