summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-18 19:21:57 +0100
committerAotrix <[email protected]>2025-03-18 19:21:57 +0100
commit332c0ffde6d60b7bac3cb14df31cbae3f27383a7 (patch)
tree80c22ed8f36be4399ca174c9d3ceac6da7cb2fab /src
parent9c280e05547671aa346530c4c7c0ddbc4729348f (diff)
added postgres handler
Diffstat (limited to 'src')
-rw-r--r--src/hearthstoneAPIHandler.cpp4
-rw-r--r--src/main.cpp23
-rw-r--r--src/postgresHandler.cpp25
3 files changed, 34 insertions, 18 deletions
diff --git a/src/hearthstoneAPIHandler.cpp b/src/hearthstoneAPIHandler.cpp
index 6528ed0..5dd28d4 100644
--- a/src/hearthstoneAPIHandler.cpp
+++ b/src/hearthstoneAPIHandler.cpp
@@ -38,8 +38,8 @@ HearthstoneAPIHandler::extract_string_with_regex(const std::string &t_str,
}
void HearthstoneAPIHandler::write_new_token_info_to_file(
- const std::string &file_path) {
- std::ofstream token_file(file_path);
+ const std::string &t_file_path) {
+ std::ofstream token_file(t_file_path);
CURL *curl = curl_easy_init();
std::string token_info;
if (curl) {
diff --git a/src/main.cpp b/src/main.cpp
index 90a4fe6..6786a5b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,29 +1,20 @@
#include "hearthstoneAPIHandler.h"
+#include "postgresHandler.h"
#include <iostream>
#include <pqxx/pqxx>
-const pqxx::result execute_query(pqxx::work &t_transaction,
- std::string_view t_query) {
- return t_transaction.exec(t_query);
-}
-
-void display_query_result(pqxx::result t_r) {
- // FIXME: not flexible
- for (auto row : t_r) {
- std::cout << std::format(
- "{}; {}; {}; {}; {}", row[0].as<std::string>(),
- row[1].as<std::string>(), row[2].as<std::string>(),
- row[3].as<std::string>(), row[4].as<std::string>());
- }
-}
-
int main() {
HearthstoneAPIHandler hs_handler;
- std::cout << hs_handler.get_cards("678?locale=en_US") << std::endl;
+ // TODO: use a parser on get_cards returned value
+ std::cout << hs_handler.get_cards("678?locale=fr_FR") << std::endl;
pqxx::connection cx{
"postgresql://aotrix@localhost:5432/hearthstonegameinfo"};
pqxx::work tx{cx};
display_query_result(execute_query(tx, "SELECT * FROM cards"));
+
+ // TODO: for test purposes
+ // use get_cards output instead?
+ add_cards_to_database("{\"name\":3}", tx);
return 0;
}
diff --git a/src/postgresHandler.cpp b/src/postgresHandler.cpp
new file mode 100644
index 0000000..212202e
--- /dev/null
+++ b/src/postgresHandler.cpp
@@ -0,0 +1,25 @@
+#include "postgresHandler.h"
+#include <iostream>
+#include <regex>
+
+const pqxx::result execute_query(pqxx::work &t_transaction,
+ std::string_view t_query) {
+ return t_transaction.exec(t_query);
+}
+
+void display_query_result(const pqxx::result &t_r) {
+ const int nb_columns = t_r.columns();
+ for (const auto &row : t_r) {
+ for (int i = 0; i < nb_columns; i++) {
+ std::cout << row[i].c_str() << " | ";
+ }
+ std::cout << std::endl;
+ }
+}
+
+void add_cards_to_database(std::string_view t_cards, pqxx::work &t_tx) {
+ // TODO: to complete
+ std::cout << "adding cards..." << std::endl;
+ std::regex key_regex; // TODO: to define
+ std::cout << t_cards.substr(1, 6) << std::endl;
+}