summaryrefslogtreecommitdiff
path: root/2025/fetch.rs
blob: 6f94ec8907ec52c80d12175981664747eabbc684 (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
30
use std::{env, str::pattern::Pattern, sync::Arc};

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

const YEAR: usize = 2025;

pub fn fetch(lv: usize, p: impl Pattern) -> 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}/input"))
        .send()
        .unwrap()
        .text()
        .unwrap()
        .split(p)
        .map(|s| s.to_string())
        .filter(|s| !s.is_empty())
        .collect()
}