kopia lustrzana https://gitlab.com/tomaszg/geostat
Support in geodb for ocde and ocus
rodzic
19df0988be
commit
6b88624da6
65
geodb.cpp
65
geodb.cpp
|
@ -2,6 +2,8 @@
|
|||
#include "ocdb.h"
|
||||
#include "okapi.h"
|
||||
|
||||
#include "config_user_key.h"
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sqlite3.h>
|
||||
|
@ -10,16 +12,27 @@
|
|||
|
||||
using json = nlohmann::json;
|
||||
|
||||
const std::string Database = "ocpl.sqlite";
|
||||
const std::string Database_pl = "ocpl.sqlite";
|
||||
const std::string Database_de = "ocde.sqlite";
|
||||
const std::string Database_us = "ocus.sqlite";
|
||||
const std::string ocpl_url = "https://opencaching.pl/okapi/";
|
||||
const std::string ocde_url = "https://www.opencaching.de/okapi/";
|
||||
const std::string ocus_url = "http://www.opencaching.us/okapi/";
|
||||
// const std::string ocnl_url = "http://www.opencaching.nl/okapi/";
|
||||
// const std::string ocro_url = "http://www.opencaching.ro/okapi/";
|
||||
// const std::string ocuk_url = "https://opencache.uk/okapi/";
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string Dump_path;
|
||||
std::string Database;
|
||||
std::string okapi_url;
|
||||
std::string okapi_key;
|
||||
bool update = 0;
|
||||
|
||||
int o;
|
||||
while ((o = getopt(argc, argv, "i:ud:h?")) != -1)
|
||||
while ((o = getopt(argc, argv, "pdui:cD:h?")) != -1)
|
||||
switch (o) {
|
||||
case 'd':
|
||||
case 'D':
|
||||
try {
|
||||
if (std::stoi(optarg) > 0) {
|
||||
Debug::set_debug_level(std::stoi(optarg));
|
||||
|
@ -35,28 +48,62 @@ int main(int argc, char** argv) {
|
|||
if (!Dump_path.ends_with('/'))
|
||||
Dump_path.push_back('/');
|
||||
break;
|
||||
case 'u':
|
||||
case 'c':
|
||||
update = 1;
|
||||
break;
|
||||
case 'd':
|
||||
if (!Database.empty()) {
|
||||
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
Database = Database_de;
|
||||
okapi_url = ocde_url;
|
||||
okapi_key = ocde_key;
|
||||
break;
|
||||
case 'p':
|
||||
if (!Database.empty()) {
|
||||
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
Database = Database_pl;
|
||||
okapi_url = ocpl_url;
|
||||
okapi_key = ocpl_key;
|
||||
break;
|
||||
case 'u':
|
||||
if (!Database.empty()) {
|
||||
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
Database = Database_us;
|
||||
okapi_url = ocus_url;
|
||||
okapi_key = ocus_key;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
std::cout << "Usage: geodb [-i path] [-uh]\n";
|
||||
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-c\tupdate database with changelogs grabbed via OKAPI\n";
|
||||
std::cout << "\t-h\tdisplay this help screen\n";
|
||||
std::cout << "\t-p\t\tuse opencaching.pl\n";
|
||||
std::cout << "\t-d\t\tuse opencaching.de\n";
|
||||
std::cout << "\t-u\t\tuse opencaching.us\n";
|
||||
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (Database.empty()) {
|
||||
std::cout << "You need to specify one of the options \"-d\", \"-p\", \"-u\".\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
OCdb db(Database);
|
||||
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);
|
||||
Okapi OK(okapi_url, okapi_key);
|
||||
db.update(OK);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue