geostat/geodb.cpp

94 wiersze
2.2 KiB
C++
Czysty Zwykły widok Historia

#include "debug.h"
#include "ocdb.h"
#include "okapi.h"
#include "common.h"
2020-11-14 17:46:03 +00:00
#include "config_user_key.h"
#include <string>
#include <fstream>
#include <sqlite3.h>
#include <unistd.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main(int argc, char** argv) {
2019-09-30 23:47:14 +00:00
std::string Dump_path;
bool update = 0;
2023-08-30 14:40:12 +00:00
Service service = none;
int o;
2020-11-14 17:46:03 +00:00
while ((o = getopt(argc, argv, "pdui:cD:h?")) != -1)
switch (o) {
2020-11-14 17:46:03 +00:00
case 'D':
try {
if (std::stoi(optarg) > 0) {
Debug::set_debug_level(std::stoi(optarg));
}
}
catch (...) {
std::cout << "Option \"-d\" requires a valid number as an argument\n";
std::exit(EXIT_FAILURE);
}
break;
2019-09-30 23:47:14 +00:00
case 'i':
Dump_path = optarg;
2019-10-01 15:18:43 +00:00
if (!Dump_path.ends_with('/'))
2019-09-30 23:47:14 +00:00
Dump_path.push_back('/');
break;
2020-11-14 17:46:03 +00:00
case 'c':
2019-09-30 23:47:14 +00:00
update = 1;
break;
2020-11-14 17:46:03 +00:00
case 'd':
2023-08-30 14:40:12 +00:00
if (service != none) {
2020-11-14 17:46:03 +00:00
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE);
}
2023-08-30 14:40:12 +00:00
service = ocde;
2020-11-14 17:46:03 +00:00
break;
case 'p':
2023-08-30 14:40:12 +00:00
if (service != none) {
2020-11-14 17:46:03 +00:00
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE);
}
2023-08-30 14:40:12 +00:00
service = ocpl;
2020-11-14 17:46:03 +00:00
break;
case 'u':
2023-08-30 14:40:12 +00:00
if (service != none) {
2020-11-14 17:46:03 +00:00
std::cout << "Options \"-d\", \"-p\", \"-u\" are mutually exclusive.\n";
std::exit(EXIT_FAILURE);
}
2023-08-30 14:40:12 +00:00
service = ocus;
2020-11-14 17:46:03 +00:00
break;
case 'h':
case '?':
default:
2019-11-18 15:06:20 +00:00
std::cout << "Usage: geodb [-i path] [-uh]\n";
2019-09-30 23:47:14 +00:00
std::cout << "Manage local Opencaching database.\n\n";
std::cout << "\t-i folder\tinitialize database from dump located in given folder\n";
2020-11-14 17:46:03 +00:00
std::cout << "\t-c\tupdate database with changelogs grabbed via OKAPI\n";
2019-09-30 23:47:14 +00:00
std::cout << "\t-h\tdisplay this help screen\n";
2020-11-14 17:46:03 +00:00
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";
2019-09-30 23:47:14 +00:00
std::exit(EXIT_FAILURE);
}
2023-08-30 14:40:12 +00:00
if (service == none) {
2020-11-14 17:46:03 +00:00
std::cout << "You need to specify one of the options \"-d\", \"-p\", \"-u\".\n";
std::exit(EXIT_FAILURE);
}
2023-08-30 14:40:12 +00:00
OCdb db(service);
2019-09-30 23:47:14 +00:00
if (!Dump_path.empty())
db.init(Dump_path);
2019-11-11 20:12:06 +00:00
2019-09-30 23:47:14 +00:00
if (update) {
2023-08-30 14:40:12 +00:00
Okapi OK(service);
2020-11-14 17:46:03 +00:00
db.update(OK);
2019-09-30 23:47:14 +00:00
}
Debug(2) << "Database now at revision: " << db.get_revision();
}