diff --git a/src/marks.cpp b/src/marks.cpp index e8167b7..2847465 100644 --- a/src/marks.cpp +++ b/src/marks.cpp @@ -32,11 +32,11 @@ void win_show(WINDOW *win, wchar_t *label, int label_color, int width, int height, json marks_json, int SubjectIndex); void marks_page() { - // DONT FORGET TO UNCOMMENT - json resp_from_api = bakaapi::get_data_from_endpoint("api/3/marks"); - // std::ifstream f("test-data/marks3.json"); - // json resp_from_api = json::parse(f); - + json resp_from_api; + { + std::string endpoint = "api/3/marks"; + resp_from_api = bakaapi::get_data_from_endpoint(endpoint); + } WINDOW **my_wins; size_t size_my_wins = resp_from_api["Subjects"].size(); my_wins = new (std::nothrow) WINDOW *[size_my_wins]; diff --git a/src/net.cpp b/src/net.cpp index f96b659..c6af804 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -162,11 +162,14 @@ void is_access_token_empty() { } // supports all endpoints that only require access_token -json get_data_from_endpoint(std::string endpoint) { +json get_data_from_endpoint(std::string &endpoint, std::string additional_data) { is_access_token_empty(); access_token_refreshed: std::string req_data = std::format("Authorization=Bearer&access_token={}", access_token); + if(!additional_data.empty()) { + req_data.append(std::format("&{}", additional_data)); + } auto [response, http_code] = send_curl_request(endpoint, GET, req_data); diff --git a/src/net.h b/src/net.h index 4557c1c..ed81aac 100644 --- a/src/net.h +++ b/src/net.h @@ -11,6 +11,6 @@ extern CURL *curl; namespace bakaapi { void login(std::string username, std::string password); void refresh_access_token(); -json get_data_from_endpoint(std::string endpoint); +json get_data_from_endpoint(std::string &endpoint, std::string data = ""); } // namespace bakaapi #endif \ No newline at end of file diff --git a/src/timetable.cpp b/src/timetable.cpp index 07113c2..9e8d52d 100644 --- a/src/timetable.cpp +++ b/src/timetable.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -80,11 +81,15 @@ json *find_atom_by_indexes(json &resp_from_api, uint8_t day_index, } void timetable_page() { - // DONT FORGET TO UNCOMMENT + const auto dateSelected = std::chrono::system_clock::now(); + std::time_t date_time_t = std::chrono::system_clock::to_time_t(dateSelected); + std::tm local_time = *std::localtime(&date_time_t); + std::stringstream date_stringstream; + date_stringstream << std::put_time(&local_time, "%Y-%m-%d"); + std::string date_string = "date=" + date_stringstream.str(); + std::string endpoint = "api/3/timetable/actual"; json resp_from_api = - bakaapi::get_data_from_endpoint("api/3/timetable/actual"); - /*std::ifstream f("test-data/timetable.json"); - json resp_from_api = json::parse(f);*/ + bakaapi::get_data_from_endpoint(endpoint, date_string); // this may be unnecessary but i dont have enaugh data to test it // it sorts the hours by start time