Pull the AoC leaderboard API

This commit is contained in:
Savanni D'Gerinel 2022-11-26 22:37:13 -05:00
parent a014b25947
commit 576df264f9
4 changed files with 1223 additions and 0 deletions

1177
challenge/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
challenge/Cargo.toml Normal file
View File

@ -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" ] }

34
challenge/src/main.rs Normal file
View File

@ -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);
}

View File

@ -23,6 +23,8 @@
pkgs.mkShell { pkgs.mkShell {
name = "aoc-devshell"; name = "aoc-devshell";
buildInputs = [ buildInputs = [
pkgs.pkg-config
pkgs.openssl
rust rust
]; ];
}; };