Compare commits
No commits in common. "24aa979a696498cb381e173a6fe8f1962fd39046" and "522b6fa5173c01ca8ef2338b2da45bb8e1f1738e" have entirely different histories.
24aa979a69
...
522b6fa517
@ -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() {
|
||||
json resp_from_api;
|
||||
{
|
||||
std::string endpoint = "api/3/marks";
|
||||
resp_from_api = bakaapi::get_data_from_endpoint(endpoint);
|
||||
}
|
||||
// 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);
|
||||
|
||||
WINDOW **my_wins;
|
||||
size_t size_my_wins = resp_from_api["Subjects"].size();
|
||||
my_wins = new (std::nothrow) WINDOW *[size_my_wins];
|
||||
|
@ -162,14 +162,11 @@ void is_access_token_empty() {
|
||||
}
|
||||
|
||||
// supports all endpoints that only require access_token
|
||||
json get_data_from_endpoint(std::string &endpoint, std::string additional_data) {
|
||||
json get_data_from_endpoint(std::string endpoint) {
|
||||
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, std::string data = "");
|
||||
json get_data_from_endpoint(std::string endpoint);
|
||||
} // namespace bakaapi
|
||||
#endif
|
@ -4,24 +4,17 @@
|
||||
#include "helper_funcs.h"
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <curses.h>
|
||||
#include <cwchar>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <ncurses.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <panel.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
using nlohmann::json;
|
||||
#define BOTTOM_PADDING 5
|
||||
|
||||
@ -87,20 +80,11 @@ json *find_atom_by_indexes(json &resp_from_api, uint8_t day_index,
|
||||
}
|
||||
|
||||
void timetable_page() {
|
||||
auto dateSelected = std::chrono::system_clock::now();
|
||||
reload_for_new_week:
|
||||
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";
|
||||
|
||||
// DONT FORGET TO UNCOMMENT
|
||||
json resp_from_api =
|
||||
bakaapi::get_data_from_endpoint(endpoint, date_string);
|
||||
bakaapi::get_data_from_endpoint("api/3/timetable/actual");
|
||||
/*std::ifstream f("test-data/timetable.json");
|
||||
json resp_from_api = json::parse(f);*/
|
||||
|
||||
// this may be unnecessary but i dont have enaugh data to test it
|
||||
// it sorts the hours by start time
|
||||
@ -264,46 +248,7 @@ void timetable_page() {
|
||||
}
|
||||
attron(COLOR_PAIR(COLOR_BLUE));
|
||||
mvprintw(LINES - 2, 0,
|
||||
"Arrows/hjkl to select | ENTER to show info | p/n to select weeks |F1 to exit");
|
||||
{
|
||||
std::tm end_week = local_time;
|
||||
std::tm start_week = local_time;
|
||||
|
||||
// Convert tm_wday (0-6) to API day format (1-7)
|
||||
int current_wday = (local_time.tm_wday == 0) ? 7 : local_time.tm_wday;
|
||||
|
||||
// Get days of week from API (1-7 format where Monday is 1)
|
||||
uint8_t start_day = resp_from_api["Days"][0]["DayOfWeek"].get<uint8_t>();
|
||||
uint8_t end_day = resp_from_api["Days"][resp_from_api["Days"].size() - 1]["DayOfWeek"].get<uint8_t>();
|
||||
|
||||
// Calculate days back to start day (handles week wraparound)
|
||||
int days_back = (current_wday >= start_day)
|
||||
? (current_wday - start_day)
|
||||
: (current_wday + 7 - start_day);
|
||||
|
||||
// Calculate days forward to end day (handles week wraparound)
|
||||
int days_forward = (current_wday <= end_day)
|
||||
? (end_day - current_wday)
|
||||
: (end_day + 7 - current_wday);
|
||||
|
||||
// Adjust dates
|
||||
start_week.tm_mday -= days_back;
|
||||
end_week.tm_mday += days_forward;
|
||||
|
||||
// Normalize the dates
|
||||
std::mktime(&start_week);
|
||||
std::mktime(&end_week);
|
||||
|
||||
// Format the dates as strings
|
||||
std::stringstream start_week_strstream, end_week_strstream;
|
||||
start_week_strstream << std::put_time(&start_week, "%d.%m.%Y");
|
||||
end_week_strstream << std::put_time(&end_week, "%d.%m.%Y");
|
||||
|
||||
// kern. developer approved ↓↓
|
||||
mvprintw(LINES - 2, COLS - (start_week_strstream.str().length() + 3 + end_week_strstream.str().length()),
|
||||
"%s", (start_week_strstream.str() + " - " + end_week_strstream.str()).c_str());
|
||||
|
||||
}
|
||||
"Arrows/hjkl to select | ENTER to show info | F1 to exit");
|
||||
attroff(COLOR_PAIR(COLOR_BLUE));
|
||||
|
||||
update_panels();
|
||||
@ -359,14 +304,6 @@ mvprintw(LINES - 2, COLS - (start_week_strstream.str().length() + 3 + end_week_s
|
||||
case 'l':
|
||||
selected_cell.x++;
|
||||
break;
|
||||
case 'p':
|
||||
dateSelected = dateSelected - std::chrono::days(7);
|
||||
goto reload_for_new_week;
|
||||
break;
|
||||
case 'n':
|
||||
dateSelected = dateSelected + std::chrono::days(7);
|
||||
goto reload_for_new_week;
|
||||
break;
|
||||
case 10: // ENTER
|
||||
json *atom = find_atom_by_indexes(resp_from_api, selected_cell.y,
|
||||
selected_cell.x, HourIdLookupTable);
|
||||
|
Loading…
x
Reference in New Issue
Block a user