From 5ca319730e4755374142ef5d6c409d5f61ae2944 Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Tue, 1 Oct 2019 01:47:14 +0200 Subject: [PATCH] Add some options to geodb --- geodb.cpp | 75 +++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/geodb.cpp b/geodb.cpp index 599e0b2..badb494 100644 --- a/geodb.cpp +++ b/geodb.cpp @@ -12,12 +12,14 @@ using json = nlohmann::json; const std::string Database = "ocpl.sqlite"; -const std::string Dump_path = "/home/tomaszg/src/geo/dump_mini/"; + int main(int argc, char** argv) { + std::string Dump_path; + bool update = 0; int o; - while ((o = getopt(argc, argv, "d:h?")) != -1) + while ((o = getopt(argc, argv, "i:ud:h?")) != -1) switch (o) { case 'd': try { @@ -31,30 +33,14 @@ int main(int argc, char** argv) { std::exit(EXIT_FAILURE); } break; -// case 'g': -// gpx_file = optarg; -// break; -// case 'p': -// use_ocpl = 1; -// break; -// case 'u': -// ocpl_user = optarg; -// break; -// case 'M': -// show_minmax = 1; -// break; -// case 'D': -// show_dist = 1; -// break; -// case 'O': -// show_owners = 1; -// break; -// case 'Y': -// show_types = 1; -// break; -// case 'H': -// heat_file = optarg; -// break; + case 'i': + Dump_path = optarg; + if (!Dump_path.ends_with='/') + Dump_path.push_back('/'); + break; + case 'u': + update = 1; + break; // case 's': // try { // if (std::stoi(optarg) > 0) { @@ -82,31 +68,20 @@ int main(int argc, char** argv) { case '?': default: std::cout << "Usage: ???\n"; -// std::cout << "Generate stats from Opencaching data or GPX files.\n\n"; -// std::cout << " * Data source:\n"; -// std::cout << "\t-p\tuse Opencaching.pl\n"; -// std::cout << "\t-u user\tuser for Opencaching\n"; -// std::cout << "\t-g file\tuse specified gpx file\n"; -// std::cout << " * Output:\n"; -// std::cout << "\t-M\tprint geographically extreme caches\n"; -// std::cout << "\t-D\tprint furthest and closest caches\n"; -// std::cout << "\t-H file\trender a heat map to a file\n"; -// std::cout << "\t-s n\tstamp size for a heat map (default = 15)\n"; -// std::cout << "\t-e\tuse exponential to flatten the heat map\n"; -// std::cout << "\t-m map\tchosen map: Poland, Poland_relief, Poland_big, Europe or a name of voivodeship (default = Poland)\n"; -// std::cout << "\t-L\tprint all caches\n"; -// std::cout << "\t-T\tprint D/T matrix\n"; -// std::cout << "\t-O\tprint owner count for found caches\n"; -// std::cout << "\t-Y\tprint types count for found caches\n"; -// std::cout << "\t-h\tdisplay this help screen\n"; -// std::exit(EXIT_FAILURE); + std::cout << "Manage local Opencaching database.\n\n"; + std::cout << "\t-i folder\tinitialize database from dump located in given folder\n"; + std::cout << "\t-u\tupdate database with changelogs grabbed via OKapi\n"; + std::cout << "\t-h\tdisplay this help screen\n"; + std::exit(EXIT_FAILURE); } OCdb db(Database); - db.init(Dump_path); - -// std::string ocpl_url = "https://opencaching.pl/okapi/"; -// #include "config_user.h" -// Okapi OCpl(ocpl_url, ocpl_key); -// db.update(OCpl); + if (!Dump_path.empty()) + db.init(Dump_path); + if (update) { + std::string ocpl_url = "https://opencaching.pl/okapi/"; + #include "config_user_key.h" + Okapi OCpl(ocpl_url, ocpl_key); + db.update(OCpl); + } }