-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-Inputs.ps1
39 lines (30 loc) · 1.19 KB
/
Get-Inputs.ps1
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
31
32
33
34
35
36
37
38
39
# Take the session token as a mandatory parameter, and take the year and day as optional parameters.
# If the year and day are not specified, then get all inputs for all years and days.
# If the year is specified, but the day is not, then get all inputs for the specified year.
param (
[Parameter(Mandatory = $true)]
[string]$SessionToken,
[Parameter(Mandatory = $false)]
[int]$Year,
[Parameter(Mandatory = $false)]
[int]$Day
)
#$BasePath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$BasePath = "."
$BaseUrl = "https://adventofcode.com"
$Headers = @{
"Cookie" = "session=$SessionToken"
}
$StartYear = if ($Year) { $Year } else { 2015 }
$EndYear = if ($Year) { $Year } else { 2022 }
$StartDay = if ($Day) { $Day } else { 1 }
$EndDay = if ($Day) { $Day } else { 25 }
for ($i = $StartYear; $i -le $EndYear; $i++) {
$YearInputsDirectoryPath = "$BasePath\inputs\$i"
New-Item -ItemType Directory -Force -Path $YearInputsDirectoryPath
for ($j = $StartDay; $j -le $EndDay; $j++) {
$Url = "$BaseUrl/$i/day/$j/input"
$OutputFile = "$YearInputsDirectoryPath\$j.txt"
Invoke-WebRequest -Uri $Url -Headers $Headers -OutFile $OutputFile
}
}