summaryrefslogtreecommitdiff
path: root/2025/fetch.rs
blob: 6c02a8f4d5edb408d709088625cd1202aee5cdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::{env, sync::Arc};

use reqwest::{Url, blocking::Client, cookie::Jar};

const YEAR: usize = 2025;

pub fn fetch(lv: usize) -> Vec<String> {
    let jar = Arc::new(Jar::default());
    jar.add_cookie_str(
        &format!(
            "session={}",
            env::var("AOC_SESSION").unwrap()
        ),
        &Url::parse("https:///adventofcode.com").unwrap(),
    );

    Client::builder()
        .cookie_provider(jar)
        .build()
        .unwrap()
        .get(format!("https://adventofcode.com/{YEAR}/day/{lv}"))
        .send()
        .unwrap()
        .text()
        .unwrap()
        .lines()
        .map(|s| s.to_string())
        .collect()
}