make timetable request specific date
This commit is contained in:
parent
522b6fa517
commit
64b4797908
@ -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];
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
@ -11,6 +11,7 @@
|
||||
#include <ncurses.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <panel.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user