-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull.ps1
31 lines (22 loc) · 894 Bytes
/
pull.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
# Install-Module -Name Microsoft.PowerShell.SecretsManagement -RequiredVersion 0.2.0-alpha1 -AllowPrerelease
Import-Module Microsoft.PowerShell.SecretsManagement
if ($args.Count -eq 0) {
Write-Host "Please provide the day number"
exit 1
}
$year = "2020"
$day = $args[0]
$outputFile = If ($day -ge 10) { "$day.txt" } Else { "0$day.txt" }
$outputPath = "./src/AoC_$year/Inputs/$outputFile"
$url = "https://adventofcode.com/$year/day/$day/input"
$cookie = New-Object System.Net.Cookie
$cookie.Name = "session"
$cookie.Value = (Get-Secret AoCSessionId -AsPlainText)
$cookie.Domain = "adventofcode.com"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.Cookies.Add($cookie);
Invoke-WebRequest $url -WebSession $session -TimeoutSec 5 -OutFile $outputPath
if (Test-Path $outputPath) {
Write-Host "Input of Day $day downloaded to $outputPath"
cat $outputPath
}