This commit is contained in:
parent
6985b21d37
commit
05d3819d56
1
src/const.h
Normal file
1
src/const.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#define VERSION "0.5"
|
||||||
@ -16,7 +16,7 @@ char *choices[] = {
|
|||||||
"Homework", "Absence", "Exit", (char *)NULL,
|
"Homework", "Absence", "Exit", (char *)NULL,
|
||||||
};
|
};
|
||||||
void (*choicesFuncs[])() = {
|
void (*choicesFuncs[])() = {
|
||||||
NULL, marks_page, NULL, NULL, NULL, NULL, NULL, NULL
|
nullptr, marks_page, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
void main_menu() {
|
void main_menu() {
|
||||||
@ -90,9 +90,11 @@ void main_menu() {
|
|||||||
menu_driver(my_menu, REQ_UP_ITEM);
|
menu_driver(my_menu, REQ_UP_ITEM);
|
||||||
break;
|
break;
|
||||||
case 10: // ENTER
|
case 10: // ENTER
|
||||||
endwin();
|
clear();
|
||||||
choicesFuncs[item_index(current_item(my_menu))]();
|
choicesFuncs[item_index(current_item(my_menu))]();
|
||||||
pos_menu_cursor(my_menu);
|
pos_menu_cursor(my_menu);
|
||||||
|
refresh();
|
||||||
|
wrefresh(my_menu_win);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wrefresh(my_menu_win);
|
wrefresh(my_menu_win);
|
||||||
|
|||||||
@ -14,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;
|
||||||
|
|
||||||
@ -145,6 +146,7 @@ void marks_page() {
|
|||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
endwin();
|
endwin();
|
||||||
|
clear();
|
||||||
delete[] my_wins;
|
delete[] my_wins;
|
||||||
delete[] my_panels;
|
delete[] my_panels;
|
||||||
delete[] original_y;
|
delete[] original_y;
|
||||||
@ -161,10 +163,13 @@ void init_wins(WINDOW **wins, int n, json marks_json) {
|
|||||||
uint8_t curent_color = 0;
|
uint8_t curent_color = 0;
|
||||||
|
|
||||||
int MaxHight = 0;
|
int MaxHight = 0;
|
||||||
|
// this loop true subjects
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
|
|
||||||
// Calculate label and max_text_length to determine window width
|
// Calculate label and max_text_length to determine window width
|
||||||
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
||||||
|
// DEBUG
|
||||||
|
// std::clog << BLUE"[LOG]" << RESET" procesing subject: " << sub_name << "\n";
|
||||||
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
||||||
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
||||||
|
|
||||||
@ -228,14 +233,9 @@ 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,
|
print_in_middle(win, 3 + i + AdditionalOffset, 0, width, CaptionBuf,COLOR_PAIR(label_color));
|
||||||
COLOR_PAIR(label_color));
|
|
||||||
|
|
||||||
strncpy(ThemeBuf,
|
strncpy(ThemeBuf,
|
||||||
rm_tr_le_whitespace(marks_json["Subjects"][SubjectIndex]["Marks"][i]["Theme"]
|
rm_tr_le_whitespace(marks_json["Subjects"][SubjectIndex]["Marks"][i]["Theme"]
|
||||||
|
|||||||
13
src/net.cpp
13
src/net.cpp
@ -16,6 +16,7 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
@ -42,8 +43,13 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
|||||||
std::string req_data) {
|
std::string req_data) {
|
||||||
std::string response;
|
std::string response;
|
||||||
std::string url = baka_api_url + endpoint;
|
std::string url = baka_api_url + endpoint;
|
||||||
|
if (type == GET) {
|
||||||
|
url.append("?" + 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);
|
||||||
@ -52,11 +58,11 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
|||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_data.c_str());
|
|
||||||
|
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
headers = curl_slist_append(
|
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
|
||||||
headers, "Content-Type: application/x-www-form-urlencoded");
|
headers = curl_slist_append(headers, std::format("User-Agent: bakatui/{}", VERSION).c_str());
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -64,6 +70,7 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
|||||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||||
break;
|
break;
|
||||||
case POST:
|
case POST:
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_data.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user