geostat/geodb.cpp

88 wiersze
2.0 KiB
C++
Czysty Zwykły widok Historia

#include "debug.h"
#include "ocdb.h"
#include "okapi.h"
#include <string>
#include <fstream>
// #include <filesystem>
#include <sqlite3.h>
#include <unistd.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
const std::string Database = "ocpl.sqlite";
2019-09-30 23:47:14 +00:00
int main(int argc, char** argv) {
2019-09-30 23:47:14 +00:00
std::string Dump_path;
bool update = 0;
int o;
2019-09-30 23:47:14 +00:00
while ((o = getopt(argc, argv, "i:ud:h?")) != -1)
switch (o) {
case 'd':
try {
if (std::stoi(optarg) > 0) {
// Debug(1) << "Setting debug level to " << optarg;
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;
if (!Dump_path.ends_with='/')
Dump_path.push_back('/');
break;
case 'u':
update = 1;
break;
// case 's':
// try {
// if (std::stoi(optarg) > 0) {
// heat_stamp_size = std::stoi(optarg);
// }
// }
// catch (...) {
// std::cout << "Option \"-s\" requires a valid number as an argument\n";
// std::exit(EXIT_FAILURE);
// }
// break;
// case 'm':
// heat_map = optarg;
// break;
// case 'e':
// heat_exp = 1;
// break;
// case 'L':
// show_list = 1;
// break;
// case 'T':
// show_dt = 1;
// break;
case 'h':
case '?':
default:
std::cout << "Usage: ???\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";
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);
2019-09-30 23:47:14 +00:00
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);
}
}