Compare commits
5 Commits
v0.7
...
24aa979a69
| Author | SHA1 | Date | |
|---|---|---|---|
| 24aa979a69 | |||
| 64b4797908 | |||
| 522b6fa517 | |||
| bee49ee7dc | |||
| accc2a79bc |
@@ -33,6 +33,9 @@ $(OBJ_PATH)/%.o: $(SRC_PATH)/%.cpp
|
|||||||
$(CPPC) $(CPPC_FLAGS) -c $< -o $@
|
$(CPPC) $(CPPC_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
install:
|
||||||
|
@install -vpm 755 -o root -g root $(BIN_PATH)/bakatui /usr/bin/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr build
|
rm -fr build
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -32,11 +32,11 @@ void win_show(WINDOW *win, wchar_t *label, int label_color, int width,
|
|||||||
int height, json marks_json, int SubjectIndex);
|
int height, json marks_json, int SubjectIndex);
|
||||||
|
|
||||||
void marks_page() {
|
void marks_page() {
|
||||||
// DONT FORGET TO UNCOMMENT
|
json resp_from_api;
|
||||||
json resp_from_api = bakaapi::get_data_from_endpoint("api/3/marks");
|
{
|
||||||
// std::ifstream f("test-data/marks3.json");
|
std::string endpoint = "api/3/marks";
|
||||||
// json resp_from_api = json::parse(f);
|
resp_from_api = bakaapi::get_data_from_endpoint(endpoint);
|
||||||
|
}
|
||||||
WINDOW **my_wins;
|
WINDOW **my_wins;
|
||||||
size_t size_my_wins = resp_from_api["Subjects"].size();
|
size_t size_my_wins = resp_from_api["Subjects"].size();
|
||||||
my_wins = new (std::nothrow) WINDOW *[size_my_wins];
|
my_wins = new (std::nothrow) WINDOW *[size_my_wins];
|
||||||
|
|||||||
+6
-12
@@ -47,8 +47,6 @@ send_curl_request(std::string endpoint, uint8_t type, std::string req_data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
// DEBUG
|
|
||||||
// std::clog << BLUE"[LOG]" << RESET" sending to endpoint: " << url << "\n";
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
|
||||||
@@ -124,8 +122,7 @@ void login(std::string username, std::string password) {
|
|||||||
|
|
||||||
access_token = resp_parsed["access_token"];
|
access_token = resp_parsed["access_token"];
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
std::cout << "access token: " << access_token << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh_access_token() {
|
void refresh_access_token() {
|
||||||
@@ -142,9 +139,7 @@ void refresh_access_token() {
|
|||||||
"token&refresh_token={}",
|
"token&refresh_token={}",
|
||||||
refresh_token);
|
refresh_token);
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
std::clog << "calling send_curl_request() with folowing req_data\n"
|
|
||||||
<< req_data << std::endl;
|
|
||||||
auto [response, http_code] = send_curl_request("api/login", POST, req_data);
|
auto [response, http_code] = send_curl_request("api/login", POST, req_data);
|
||||||
if (http_code != 200) {
|
if (http_code != 200) {
|
||||||
std::cerr << RED "[ERROR] " << RESET << http_code
|
std::cerr << RED "[ERROR] " << RESET << http_code
|
||||||
@@ -167,19 +162,18 @@ void is_access_token_empty() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// supports all endpoints that only require access_token
|
// 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();
|
is_access_token_empty();
|
||||||
access_token_refreshed:
|
access_token_refreshed:
|
||||||
std::string req_data =
|
std::string req_data =
|
||||||
std::format("Authorization=Bearer&access_token={}", access_token);
|
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);
|
auto [response, http_code] = send_curl_request(endpoint, GET, req_data);
|
||||||
|
|
||||||
if (http_code != 200) {
|
if (http_code != 200) {
|
||||||
// DEBUG
|
|
||||||
std::clog << "Failed geting data from endpoint: " << endpoint
|
|
||||||
<< " code: " << http_code << "\nrequest: " << req_data
|
|
||||||
<< "\nresponse: " << response << std::endl;
|
|
||||||
refresh_access_token();
|
refresh_access_token();
|
||||||
goto access_token_refreshed;
|
goto access_token_refreshed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ extern CURL *curl;
|
|||||||
namespace bakaapi {
|
namespace bakaapi {
|
||||||
void login(std::string username, std::string password);
|
void login(std::string username, std::string password);
|
||||||
void refresh_access_token();
|
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
|
} // namespace bakaapi
|
||||||
#endif
|
#endif
|
||||||
+77
-5
@@ -4,19 +4,26 @@
|
|||||||
#include "helper_funcs.h"
|
#include "helper_funcs.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include <bits/chrono.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <panel.h>
|
#include <panel.h>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
#define BOTTOM_PADDING 3
|
#define BOTTOM_PADDING 5
|
||||||
|
|
||||||
#define DEFAULT_OFFSET 3
|
#define DEFAULT_OFFSET 3
|
||||||
|
|
||||||
@@ -80,11 +87,20 @@ json *find_atom_by_indexes(json &resp_from_api, uint8_t day_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void timetable_page() {
|
void timetable_page() {
|
||||||
// DONT FORGET TO UNCOMMENT
|
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";
|
||||||
|
|
||||||
json resp_from_api =
|
json resp_from_api =
|
||||||
bakaapi::get_data_from_endpoint("api/3/timetable/actual");
|
bakaapi::get_data_from_endpoint(endpoint, date_string);
|
||||||
/*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
|
// this may be unnecessary but i dont have enaugh data to test it
|
||||||
// it sorts the hours by start time
|
// it sorts the hours by start time
|
||||||
@@ -246,6 +262,49 @@ void timetable_page() {
|
|||||||
wattroff(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
wattroff(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
attroff(COLOR_PAIR(COLOR_BLUE));
|
||||||
|
|
||||||
update_panels();
|
update_panels();
|
||||||
doupdate();
|
doupdate();
|
||||||
@@ -300,6 +359,14 @@ void timetable_page() {
|
|||||||
case 'l':
|
case 'l':
|
||||||
selected_cell.x++;
|
selected_cell.x++;
|
||||||
break;
|
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
|
case 10: // ENTER
|
||||||
json *atom = find_atom_by_indexes(resp_from_api, selected_cell.y,
|
json *atom = find_atom_by_indexes(resp_from_api, selected_cell.y,
|
||||||
selected_cell.x, HourIdLookupTable);
|
selected_cell.x, HourIdLookupTable);
|
||||||
@@ -402,6 +469,11 @@ void timetable_page() {
|
|||||||
mvwaddwstr(infobox_window, 6, 1, Theme.c_str());
|
mvwaddwstr(infobox_window, 6, 1, Theme.c_str());
|
||||||
wattroff(infobox_window, COLOR_PAIR(COLOR_CYAN));
|
wattroff(infobox_window, COLOR_PAIR(COLOR_CYAN));
|
||||||
|
|
||||||
|
wattron(infobox_window, COLOR_PAIR(COLOR_BLUE));
|
||||||
|
mvwaddstr(infobox_window, getmaxy(infobox_window) - 2, 1,
|
||||||
|
"Press any key to close");
|
||||||
|
wattroff(infobox_window, COLOR_PAIR(COLOR_BLUE));
|
||||||
|
|
||||||
top_panel(infobox_panel);
|
top_panel(infobox_panel);
|
||||||
update_panels();
|
update_panels();
|
||||||
doupdate();
|
doupdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user