Get session cookie from ~/.config/aoc2020session so I don’t have to put it into the scheme every day

This commit is contained in:
Sven Weidauer 2020-12-12 09:02:49 +01:00
parent 34ca4c3fc2
commit 1f9aae4f16

View file

@ -1,12 +1,10 @@
import Foundation import Foundation
func loadData(day: Int) -> String { func loadData(day: Int) -> String {
guard let session = getenv("SESSION") else { let session = (try! String(contentsOf: FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/aoc2020session"))).trimmingCharacters(in: .whitespacesAndNewlines)
fatalError("Missing session env var")
}
var request = URLRequest(url: URL(string: "https://adventofcode.com/2020/day/\(day)/input")!) var request = URLRequest(url: URL(string: "https://adventofcode.com/2020/day/\(day)/input")!)
request.setValue("session=\(String(cString: session))", forHTTPHeaderField: "Cookie") request.setValue("session=\(session)", forHTTPHeaderField: "Cookie")
var result: String? = nil var result: String? = nil