|
|
@ -3,7 +3,7 @@ |
|
|
|
#include "days/days.h" |
|
|
|
#include "days/days.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> getInput(int day, std::string key, bool useTestInput){ |
|
|
|
std::vector<std::string> getInput(int day, std::string key, bool useTestInput) { |
|
|
|
std::vector<std::string> result; |
|
|
|
std::vector<std::string> result; |
|
|
|
|
|
|
|
|
|
|
|
char dayStrPadded[3]; |
|
|
|
char dayStrPadded[3]; |
|
|
@ -11,14 +11,14 @@ std::vector<std::string> getInput(int day, std::string key, bool useTestInput){ |
|
|
|
std::string postfix = useTestInput ? "_testInput.txt" : "_input.txt"; |
|
|
|
std::string postfix = useTestInput ? "_testInput.txt" : "_input.txt"; |
|
|
|
std::string localFilePath = "input/" + std::string(dayStrPadded) + postfix; |
|
|
|
std::string localFilePath = "input/" + std::string(dayStrPadded) + postfix; |
|
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::exists({localFilePath})){ |
|
|
|
if (!std::filesystem::exists({localFilePath})) { |
|
|
|
if (key.empty()) |
|
|
|
if (key.empty()) |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
std::string dayStr = std::to_string(day); |
|
|
|
std::string dayStr = std::to_string(day); |
|
|
|
std::string url = "https://adventofcode.com/2021/day/" + dayStr + "/input"; |
|
|
|
std::string url = "https://adventofcode.com/2021/day/" + dayStr + "/input"; |
|
|
|
std::cout << "Input does not exist. Fetching from " + url << std::endl; |
|
|
|
std::cout << "Input does not exist. Fetching from " + url << std::endl; |
|
|
|
std::ofstream file(localFilePath); |
|
|
|
std::ofstream file(localFilePath); |
|
|
|
file << cpr::Get(cpr::Url {url}, cpr::Cookies{{"session", key}}).text; |
|
|
|
file << cpr::Get(cpr::Url{url}, cpr::Cookies{{"session", key}}).text; |
|
|
|
file.close(); |
|
|
|
file.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ std::vector<std::string> getInput(int day, std::string key, bool useTestInput){ |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string getSessionKey(){ |
|
|
|
std::string getSessionKey() { |
|
|
|
std::string key; |
|
|
|
std::string key; |
|
|
|
std::ifstream file("session"); |
|
|
|
std::ifstream file("session"); |
|
|
|
if (!file.good()) |
|
|
|
if (!file.good()) |
|
|
@ -50,11 +50,11 @@ int main(int argc, char *argv[]) { |
|
|
|
auto days = getAllDays(); |
|
|
|
auto days = getAllDays(); |
|
|
|
std::filesystem::create_directory("input"); |
|
|
|
std::filesystem::create_directory("input"); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; i++){ |
|
|
|
for (int i = 1; i < argc; i++) { |
|
|
|
int dayNum = std::stoi(argv[i]); |
|
|
|
int dayNum = std::stoi(argv[i]); |
|
|
|
std::cout << "Running day " << dayNum << std::endl; |
|
|
|
std::cout << "Running day " << dayNum << std::endl; |
|
|
|
Input input = getInput(dayNum, key, useTestInput); |
|
|
|
Input input = getInput(dayNum, key, useTestInput); |
|
|
|
Day* day = days[dayNum - 1]; |
|
|
|
Day *day = days[dayNum - 1]; |
|
|
|
int code = day->run(input); |
|
|
|
int code = day->run(input); |
|
|
|
if (code != 0) |
|
|
|
if (code != 0) |
|
|
|
return code; |
|
|
|
return code; |
|
|
@ -64,5 +64,3 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|