diff options
| -rw-r--r-- | include/postgresHandler.h | 2 | ||||
| -rw-r--r-- | resources/token_info.txt | 2 | ||||
| -rw-r--r-- | src/postgresHandler.cpp | 17 |
3 files changed, 12 insertions, 9 deletions
diff --git a/include/postgresHandler.h b/include/postgresHandler.h index 2be688e..3c77824 100644 --- a/include/postgresHandler.h +++ b/include/postgresHandler.h @@ -4,8 +4,6 @@ const pqxx::result execute_query(pqxx::work &t_transaction, std::string_view t_query); -void display_query_result(const pqxx::result &t_r); - void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx); void refresh_cards_table(); diff --git a/resources/token_info.txt b/resources/token_info.txt index e18f2ba..d9fee10 100644 --- a/resources/token_info.txt +++ b/resources/token_info.txt @@ -1 +1 @@ -EUFbkUjCXKrSY8z1dUDjS9oHKSrho6LDHT 1743163065
\ No newline at end of file +EUO9LAUZ7FqGUl0dVcpd6JDj3L5vp9GooV 1748519263
\ No newline at end of file diff --git a/src/postgresHandler.cpp b/src/postgresHandler.cpp index 26828bc..662a6a3 100644 --- a/src/postgresHandler.cpp +++ b/src/postgresHandler.cpp @@ -2,6 +2,7 @@ #include "hearthstoneAPIHandler.h" #include <cctype> #include <cstddef> +#include <cstdint> #include <cstdlib> #include <iostream> #include <regex> @@ -19,14 +20,15 @@ const pqxx::result execute_query(pqxx::work &t_transaction, return t_transaction.exec(t_query); } -void display_query_result(const pqxx::result &t_r) { +std::ostream &operator<<(std::ostream &t_ostream, const pqxx::result &t_r) { const int nb_columns = t_r.columns(); + t_ostream << "| "; for (const auto &row : t_r) { for (int i = 0; i < nb_columns; i++) { - std::cout << row[i].c_str() << " | "; + t_ostream << row[i].c_str() << " | "; } - std::cout << std::endl; } + return t_ostream; } static const unsigned int @@ -143,16 +145,19 @@ void refresh_cards_table() { std::sregex_iterator(cards.begin(), cards.end(), key_regex); auto nb_pages_end = std::sregex_iterator(); if (nb_pages_begin != nb_pages_end) { - int nb_pages = std::stoi((*nb_pages_begin)[1].str()); + uint32_t nb_pages = std::stoi((*nb_pages_begin)[1].str()); + std::cout << "number of pages: " << nb_pages << std::endl; // FIXME: [Process exited 139] // for (int i = 2; i < nb_pages; i++) { - for (int i = 2; i < 4; i++) { + for (uint32_t i = 2; i < 3; i++) { cards = hs_handler.get_cards(std::format( "/?locale=fr_FR&gameMode=constructed&page={}", i)); add_cards_to_database(cards, tx); } } - display_query_result(execute_query(tx, "SELECT COUNT(*) FROM cards")); + std::cout << "number of cards in database: " + << execute_query(tx, "SELECT COUNT(*) FROM cards") + << std::endl; tx.commit(); } catch (pqxx::sql_error const &e) { std::cerr << "SQL error: " << e.what() << std::endl; |
