From 1f9aae4f165bd3130314766d71aafcfaca3668f4 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sat, 12 Dec 2020 09:02:49 +0100 Subject: [PATCH] =?UTF-8?q?Get=20session=20cookie=20from=20~/.config/aoc20?= =?UTF-8?q?20session=20so=20I=20don=E2=80=99t=20have=20to=20put=20it=20int?= =?UTF-8?q?o=20the=20scheme=20every=20day?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/LoadData.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/LoadData.swift b/common/LoadData.swift index 322be0f..1ad85c6 100644 --- a/common/LoadData.swift +++ b/common/LoadData.swift @@ -1,12 +1,10 @@ import Foundation func loadData(day: Int) -> String { - guard let session = getenv("SESSION") else { - fatalError("Missing session env var") - } + let session = (try! String(contentsOf: FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/aoc2020session"))).trimmingCharacters(in: .whitespacesAndNewlines) 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