add komens skeleton
Some checks are pending
/ sync-to-origin (push) Waiting to run

This commit is contained in:
PoliEcho 2025-04-04 18:01:50 +02:00
parent 74dc204f22
commit b005631d20
5 changed files with 53 additions and 10 deletions

41
src/komens.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "const.h"
#include "helper_funcs.h"
#include "memory.h"
#include "net.h"
#include <bits/chrono.h>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <curses.h>
#include <cwchar>
#include <ncurses.h>
#include <nlohmann/json.hpp>
#include <panel.h>
#include <string>
#include <sys/types.h>
#include <vector>
using nlohmann::json;
std::vector<allocation> komens_allocated;
void komens_page() {
current_allocated = &komens_allocated;
json resp_from_api;
{
std::string endpoint = "api/3/komens";
resp_from_api = bakaapi::get_data_from_endpoint(endpoint, GET);
}
setlocale(LC_ALL, "");
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
/* Initialize all the colors */
for (uint8_t i = 0; i < 8; i++) {
init_pair(i, i, COLOR_BLACK);
}
}

View File

@ -40,7 +40,7 @@ void marks_page() {
json resp_from_api;
{
std::string endpoint = "api/3/marks";
resp_from_api = bakaapi::get_data_from_endpoint(endpoint);
resp_from_api = bakaapi::get_data_from_endpoint(endpoint, GET);
}
size_t size_my_wins = resp_from_api["Subjects"].size();
WINDOW **my_wins = new (std::nothrow) WINDOW *[size_my_wins];

View File

@ -20,12 +20,6 @@
using nlohmann::json;
// metods
enum metod {
GET,
POST,
};
std::string access_token;
CURL *curl = curl_easy_init();
@ -159,7 +153,7 @@ 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, metod metod,
std::string additional_data) {
is_access_token_empty();
access_token_refreshed:

View File

@ -5,12 +5,19 @@
#ifndef _ba_ne_hg_
#define _ba_ne_hg_
// metods
enum metod {
GET,
POST,
};
using nlohmann::json;
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, metod metod,
std::string additional_data = "");
} // namespace bakaapi
#endif

View File

@ -100,7 +100,8 @@ reload_for_new_week:
std::string date_string = "date=" + date_stringstream.str();
std::string endpoint = "api/3/timetable/actual";
json resp_from_api = bakaapi::get_data_from_endpoint(endpoint, date_string);
json resp_from_api =
bakaapi::get_data_from_endpoint(endpoint, GET, date_string);
// this may be unnecessary but i dont have enaugh data to test it
// it sorts the hours by start time