aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr/main.cpp
blob: 278d62f8f4d1e5229543e4c9c835caafdee1c91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <cstdlib>
#include <iostream>

#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<PokemonCard*> 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<std::string> card_ids = zip_export.import_csv(csv_file);
	std::vector<PokemonCard*> 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 <enter>

		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;
}