#include #include #include "Pokedex.h" #include "PokemonCard.h" #include "ZipExport.h" using std::endl; using std::cout; using std::cin; Pokedex* g_pokedex = nullptr; int interactive_mode() { cout << "entering interactive mode..." << endl; std::string search_query; for(;;) { cout << "card id or name?: "; if (!std::getline(cin, search_query)) break; std::vector cards = g_pokedex->search_cards(search_query); size_t card_count = cards.size(); if (card_count == 0) { cout << "no cards found" << endl; } else if (card_count == 1) { cards[0]->fetch_market_value(); cout << "found card:" << endl << *cards[0]; } else { cout << "found cards:" << endl; for (PokemonCard* card : cards) cout << card->short_identifier() << endl; } } return EXIT_SUCCESS; } int export_mode(int argc, char** argv) { cout << "entering export mode..." << endl; std::string csv_file = argv[1]; std::string zip_file = argc == 3 ? argv[2] : ""; ZipExport zip_export; zip_export.set_pokedex(g_pokedex); std::vector card_ids = zip_export.import_csv(csv_file); std::vector cards; for (std::string card_id : card_ids) { PokemonCard* card = g_pokedex->get_card_by_id(card_id); if (card == nullptr) { cout << "could not find card with id " << card_id << endl; continue; } card->fetch_market_value(); cards.push_back(card); } double total_value = 0.f; for (PokemonCard* card : cards) { cout << card->short_identifier() << " currently sells for " << card->value << endl; total_value += card->value; } cout << "sum value of cards: " << total_value << endl; if (zip_file.size() == 0) { cout << "export as zip? [Y/n]: "; std::string export_yn; if (!std::getline(cin, export_yn)) return EXIT_SUCCESS; // exit if EOF (ctrl-d) if (export_yn.size() > 0 && (export_yn[0] | (1 << 5)) != 'y') return EXIT_SUCCESS; // exit if input is not 'Y', 'y', or cout << "zip file location?: "; if (!std::getline(cin, zip_file)) return EXIT_FAILURE; } cout << "exporting as zip..." << endl; zip_export.export_zip(zip_file, cards); return EXIT_SUCCESS; } int main(int argc, char** argv) { g_pokedex = new Pokedex(); if (argc == 1) { // no arguments specified return interactive_mode(); } else if (argc == 2 || argc == 3) { return export_mode(argc, argv); } else { // three or more arguments cout << "too many arguments specified!" << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }