|
|
@ -1,43 +1,58 @@ |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
#include <filesystem> |
|
|
|
#include <filesystem> |
|
|
|
#include "days.h" |
|
|
|
#include "days.h" |
|
|
|
//#include <cpr/cpr.h>
|
|
|
|
#include <cpr/cpr.h> |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> getInput(int day){ |
|
|
|
std::vector<std::string> getInput(int day, std::string key){ |
|
|
|
|
|
|
|
std::vector<std::string> result; |
|
|
|
|
|
|
|
|
|
|
|
char dayStrPadded[3]; |
|
|
|
char dayStrPadded[3]; |
|
|
|
sprintf(dayStrPadded, "%02u", day); |
|
|
|
sprintf(dayStrPadded, "%02u", day); |
|
|
|
std::string localFilePath = "input/" + std::string(dayStrPadded) + "_input.txt"; |
|
|
|
std::string localFilePath = "input/" + std::string(dayStrPadded) + "_input.txt"; |
|
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::exists({localFilePath})){ |
|
|
|
if (!std::filesystem::exists({localFilePath})){ |
|
|
|
|
|
|
|
if (key.empty()) |
|
|
|
|
|
|
|
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::string key = "sdfsd"; |
|
|
|
|
|
|
|
std::string cookie = "session=" + key; |
|
|
|
|
|
|
|
std::cout << "Input does not exist. Fetching from " + url << std::endl; |
|
|
|
std::cout << "Input does not exist. Fetching from " + url << std::endl; |
|
|
|
//cpr::Response res = cpr::Get(cpr::Url {url}, cpr::Header{{"Cookie", cookie}});
|
|
|
|
cpr::Response res = cpr::Get(cpr::Url {url}, cpr::Cookies{{"session", key}}); |
|
|
|
//std::cout << res.text << std::endl;
|
|
|
|
std::string content = res.text; |
|
|
|
|
|
|
|
std::ofstream file(localFilePath); |
|
|
|
|
|
|
|
file << content; |
|
|
|
|
|
|
|
file.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::fstream file; |
|
|
|
std::ifstream file(localFilePath); |
|
|
|
file.open(localFilePath, std::ios::in); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> result; |
|
|
|
|
|
|
|
std::string line; |
|
|
|
std::string line; |
|
|
|
while (std::getline(file, line)) |
|
|
|
while (std::getline(file, line)) |
|
|
|
result.push_back(line); |
|
|
|
result.push_back(line); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string getSessionKey(){ |
|
|
|
|
|
|
|
std::string key; |
|
|
|
|
|
|
|
std::ifstream file("session"); |
|
|
|
|
|
|
|
if (!file.good()) |
|
|
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
file >> key; |
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
return key; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string key = getSessionKey(); |
|
|
|
|
|
|
|
|
|
|
|
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::vector<std::string> input = getInput(dayNum); |
|
|
|
std::vector<std::string> input = getInput(dayNum, key); |
|
|
|
auto day = getDay(dayNum, input); |
|
|
|
auto day = getDay(dayNum, input); |
|
|
|
int code = day->run(); |
|
|
|
int code = day->run(); |
|
|
|
if (code != 0) |
|
|
|
if (code != 0) |
|
|
|