Compare commits
No commits in common. "a6ff11ff712a7601d902eff9d6e627c24a57e42c" and "50447ac8cd168d3eb9d328889cd36ee6f679c302" have entirely different histories.
a6ff11ff71
...
50447ac8cd
@ -1,7 +1,3 @@
|
|||||||
|
|
||||||
// Header guard
|
|
||||||
#ifndef RESET
|
|
||||||
|
|
||||||
#define RESET "\033[0m"
|
#define RESET "\033[0m"
|
||||||
#define BLACK "\033[30m" /* Black */
|
#define BLACK "\033[30m" /* Black */
|
||||||
#define RED "\033[31m" /* Red */
|
#define RED "\033[31m" /* Red */
|
||||||
@ -18,6 +14,4 @@
|
|||||||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
||||||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
||||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +1 @@
|
|||||||
#ifndef VERSION
|
#define VERSION "0.5"
|
||||||
|
|
||||||
#define VERSION "0.5"
|
|
||||||
#define NAME "bakatui"
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "const.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include "helper_funcs.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
void PrintHelp() {
|
|
||||||
std::cout << "Usage: " << NAME << " [OPTIONS]" << "\n"
|
|
||||||
<< "-h Show this help menu\n"
|
|
||||||
<< "-V Show version\n"
|
|
||||||
<< "-v verbose mode\n"
|
|
||||||
<< "-L Force new login\n"
|
|
||||||
<< "-S Ignore SSL cert validity\n";
|
|
||||||
safe_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintVersion() {
|
|
||||||
std::cout << NAME" " << VERSION"\n" << "License GPLv3: GNU GPL version 3 <https://gnu.org/licenses/gpl.html>.\n";
|
|
||||||
safe_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteLogin(std::string savedir_path) {
|
|
||||||
std::remove((savedir_path + "/authfile").c_str());
|
|
||||||
std::remove((savedir_path + "/urlfile").c_str());
|
|
||||||
}
|
|
10
src/flags.h
10
src/flags.h
@ -1,10 +0,0 @@
|
|||||||
#include <string>
|
|
||||||
// header guard
|
|
||||||
#ifndef _ba_fl_hg_
|
|
||||||
#define _ba_fl_hg_
|
|
||||||
|
|
||||||
void PrintHelp();
|
|
||||||
void PrintVersion();
|
|
||||||
void DeleteLogin(std::string savedir_path);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,16 +1,9 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// header guard
|
|
||||||
#ifndef _ba_hf_hg_
|
|
||||||
#define _ba_hf_hg_
|
|
||||||
|
|
||||||
void safe_exit(int code);
|
void safe_exit(int code);
|
||||||
std::string bool_to_string(bool bool_in);
|
std::string bool_to_string(bool bool_in);
|
||||||
std::string SoRAuthFile(bool save, std::string data);
|
std::string SoRAuthFile(bool save, std::string data);
|
||||||
void get_input_and_login();
|
void get_input_and_login();
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
char *string, chtype color);
|
char *string, chtype color);
|
||||||
std::string rm_tr_le_whitespace(const std::string &s);
|
std::string rm_tr_le_whitespace(const std::string &s);
|
||||||
|
|
||||||
#endif
|
|
23
src/main.cpp
23
src/main.cpp
@ -2,9 +2,9 @@
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "helper_funcs.h"
|
#include "helper_funcs.h"
|
||||||
#include "main_menu.h"
|
#include "main_menu.h"
|
||||||
|
#include "marks.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdlib>
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -12,13 +12,9 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "flags.h"
|
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
std::string baka_api_url;
|
std::string baka_api_url;
|
||||||
|
|
||||||
Config config;
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// signal handlers
|
// signal handlers
|
||||||
signal(SIGTERM, safe_exit);
|
signal(SIGTERM, safe_exit);
|
||||||
@ -29,23 +25,12 @@ int main(int argc, char **argv) {
|
|||||||
// error signal handlers
|
// error signal handlers
|
||||||
signal(SIGSEGV, safe_exit);
|
signal(SIGSEGV, safe_exit);
|
||||||
|
|
||||||
{
|
// marks_page();
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
std::string savedir_path = std::getenv("HOME");
|
std::string savedir_path = std::getenv("HOME");
|
||||||
savedir_path.append("/.local/share/bakatui");
|
savedir_path.append("/.local/share/bakatui");
|
||||||
|
|
||||||
int opt;
|
|
||||||
while ((opt = getopt(argc, argv, "hVvLS:")) != -1) {
|
|
||||||
switch (opt) {
|
|
||||||
case 'h': PrintHelp(); break;
|
|
||||||
case 'V': PrintVersion(); break;
|
|
||||||
case 'v': config.verbose = true; break;
|
|
||||||
case 'L': DeleteLogin(savedir_path); break;
|
|
||||||
case 'S': config.ignoressl = true; break;
|
|
||||||
default: std::cerr << RED"[ERROR]" << RESET" invalid option: " << (char)optopt << "\ntry: -h\n"; safe_exit(EINVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string urlfile_path = std::string(savedir_path) + "/url";
|
std::string urlfile_path = std::string(savedir_path) + "/url";
|
||||||
std::ifstream urlfile;
|
std::ifstream urlfile;
|
||||||
urlfile.open(urlfile_path);
|
urlfile.open(urlfile_path);
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "types.h"
|
|
||||||
// header guard
|
|
||||||
#ifndef _ba_ma_hg_
|
|
||||||
#define _ba_ma_hg_
|
|
||||||
|
|
||||||
extern std::string baka_api_url;
|
extern std::string baka_api_url;
|
||||||
extern Config config;
|
|
||||||
|
|
||||||
#endif
|
|
@ -12,7 +12,7 @@
|
|||||||
#define CTRLD 4
|
#define CTRLD 4
|
||||||
|
|
||||||
char *choices[] = {
|
char *choices[] = {
|
||||||
"login", "Marks", "timetable", "Komens",
|
"login", "Marks", "shedule", "Komens",
|
||||||
"Homework", "Absence", "Exit", (char *)NULL,
|
"Homework", "Absence", "Exit", (char *)NULL,
|
||||||
};
|
};
|
||||||
void (*choicesFuncs[])() = {
|
void (*choicesFuncs[])() = {
|
||||||
|
@ -1,7 +1 @@
|
|||||||
// header guard
|
void main_menu();
|
||||||
#ifndef _ba_mm_hg_
|
|
||||||
#define _ba_mm_hg_
|
|
||||||
|
|
||||||
void main_menu();
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
@ -13,6 +14,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ void win_show(WINDOW *win, char *label, int label_color, int width, int height,
|
|||||||
|
|
||||||
void marks_page() {
|
void marks_page() {
|
||||||
// DONT FORGET TO UNCOMMENT
|
// DONT FORGET TO UNCOMMENT
|
||||||
json resp_from_api = bakaapi::get_data_from_endpoint("api/3/marks");
|
json resp_from_api = bakaapi::get_grades();
|
||||||
// std::ifstream f("test-data/marks3.json");
|
// std::ifstream f("test-data/marks3.json");
|
||||||
// json resp_from_api = json::parse(f);
|
// json resp_from_api = json::parse(f);
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ void marks_page() {
|
|||||||
|
|
||||||
update_panels();
|
update_panels();
|
||||||
attron(COLOR_PAIR(4));
|
attron(COLOR_PAIR(4));
|
||||||
mvprintw(LINES - 2, 0, "Arrows/j/k to scroll | F1 to exit | {mark} [weight]");
|
mvprintw(LINES - 2, 0, "Arrows/j/k to scroll | F1 to exit");
|
||||||
attroff(COLOR_PAIR(4));
|
attroff(COLOR_PAIR(4));
|
||||||
doupdate();
|
doupdate();
|
||||||
|
|
||||||
@ -231,10 +233,7 @@ void win_show(WINDOW *win, char *label, int label_color, int width, int height,
|
|||||||
i++) {
|
i++) {
|
||||||
Caption = marks_json["Subjects"][SubjectIndex]["Marks"][i]["Caption"];
|
Caption = marks_json["Subjects"][SubjectIndex]["Marks"][i]["Caption"];
|
||||||
Caption = rm_tr_le_whitespace(Caption);
|
Caption = rm_tr_le_whitespace(Caption);
|
||||||
Caption.append(std::format(" - {{{}}} [{}]",
|
Caption.append(std::format(" - {{{}}} [{}]",marks_json["Subjects"][SubjectIndex]["Marks"][i]["MarkText"].get<std::string>(),marks_json["Subjects"][SubjectIndex]["Marks"][i]["Weight"].get<int>()));
|
||||||
marks_json["Subjects"][SubjectIndex]["Marks"][i]["MarkText"]
|
|
||||||
.get<std::string>(),marks_json["Subjects"][SubjectIndex]["Marks"][i]["Weight"].get<int>()));
|
|
||||||
|
|
||||||
strncpy(CaptionBuf, Caption.c_str(), sizeof(CaptionBuf)-1);
|
strncpy(CaptionBuf, Caption.c_str(), sizeof(CaptionBuf)-1);
|
||||||
print_in_middle(win, 3 + i + AdditionalOffset, 0, width, CaptionBuf,COLOR_PAIR(label_color));
|
print_in_middle(win, 3 + i + AdditionalOffset, 0, width, CaptionBuf,COLOR_PAIR(label_color));
|
||||||
|
|
||||||
|
@ -1,5 +1 @@
|
|||||||
// header guard
|
void marks_page();
|
||||||
#ifndef _ba_mp_hg_
|
|
||||||
#define _ba_mp_hg_
|
|
||||||
void marks_page();
|
|
||||||
#endif
|
|
12
src/net.cpp
12
src/net.cpp
@ -155,25 +155,21 @@ void refresh_access_token() {
|
|||||||
|
|
||||||
access_token = resp_parsed["access_token"];
|
access_token = resp_parsed["access_token"];
|
||||||
}
|
}
|
||||||
void is_access_token_empty() {
|
|
||||||
|
json get_grades() {
|
||||||
if(access_token.empty()) {
|
if(access_token.empty()) {
|
||||||
json authfile_parsed = json::parse(SoRAuthFile(false, ""));
|
json authfile_parsed = json::parse(SoRAuthFile(false, ""));
|
||||||
access_token = authfile_parsed["access_token"];
|
access_token = authfile_parsed["access_token"];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// supports all endpoints that only require access_token
|
|
||||||
json get_data_from_endpoint(std::string endpoint) {
|
|
||||||
is_access_token_empty();
|
|
||||||
std::string req_data =
|
std::string req_data =
|
||||||
std::format("Authorization=Bearer&access_token={}",
|
std::format("Authorization=Bearer&access_token={}",
|
||||||
access_token);
|
access_token);
|
||||||
|
|
||||||
auto [response, http_code] = send_curl_request(endpoint, GET, req_data);
|
auto [response, http_code] = send_curl_request("api/3/marks", GET, req_data);
|
||||||
|
|
||||||
if(http_code != 200) {
|
if(http_code != 200) {
|
||||||
// DEBUG
|
// DEBUG
|
||||||
std::clog << "Failed geting data from endpoint: " << endpoint << " code: " << http_code << "\nrequest: " << req_data <<"\nresponse: " << response << std::endl;
|
std::clog << "Failed geting marks code: " << http_code << "\nrequest: " << req_data <<"\nresponse: " << response << std::endl;
|
||||||
refresh_access_token();
|
refresh_access_token();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
// header guard
|
|
||||||
#ifndef _ba_ne_hg_
|
|
||||||
#define _ba_ne_hg_
|
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
@ -11,6 +8,5 @@ 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_grades();
|
||||||
} // namespace bakaapi
|
} // namespace bakaapi
|
||||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||||||
#include "timetable.h"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "net.h"
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
|
|
||||||
#define NLINES 10
|
|
||||||
#define NCOLS 40
|
|
||||||
|
|
||||||
#define DEFAULT_X_OFFSET 10
|
|
||||||
#define DEFAULT_Y_OFFSET 2
|
|
||||||
|
|
||||||
#define DEFAULT_PADDING 4
|
|
||||||
|
|
||||||
void timetable_page() {
|
|
||||||
// DONT FORGET TO UNCOMMENT
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// calculate table size
|
|
||||||
|
|
||||||
uint8_t column_number = 0;
|
|
||||||
for(uint8_t i = 0; i < resp_from_api["Days"].size(); i++) {
|
|
||||||
(resp_from_api["Days"][i]["Atoms"].size() > column_number) ? (column_number = resp_from_api["Days"][i]["Atoms"].size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
// header guard
|
|
||||||
#ifndef _ba_ti_hg_
|
|
||||||
#define _ba_ti_hg_
|
|
||||||
|
|
||||||
void timetable_page();
|
|
||||||
#endif
|
|
@ -1,9 +0,0 @@
|
|||||||
// header guard
|
|
||||||
#ifndef _ba_ty_hg_
|
|
||||||
#define _ba_ty_hg_
|
|
||||||
|
|
||||||
struct Config {
|
|
||||||
bool verbose = false;
|
|
||||||
bool ignoressl = false;
|
|
||||||
};
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user