kopia lustrzana https://gitlab.com/tomaszg/geostat
Further refactor and simplifications
rodzic
3f109a7047
commit
868b62bb2e
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <cmath>
|
||||
|
||||
|
|
22
common.h
22
common.h
|
@ -5,13 +5,22 @@
|
|||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
|
||||
class Cache;
|
||||
|
||||
enum Service {
|
||||
ocpl,
|
||||
ocde,
|
||||
ocus,
|
||||
ocro,
|
||||
ocuk,
|
||||
ocnl,
|
||||
none
|
||||
};
|
||||
|
||||
const uint Earth_radius = 6378;
|
||||
const uint Moon_dist = 384400;
|
||||
|
||||
|
@ -19,13 +28,6 @@ typedef std::vector<Cache> Caches;
|
|||
typedef std::vector<const Cache*> pCaches;
|
||||
typedef std::multimap<std::time_t, const Cache*> Date_Caches;
|
||||
|
||||
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/";
|
||||
|
||||
const std::string flag_pl = "https://wiki.opencaching.eu/images/b/b7/Oc-pl.png";
|
||||
const std::string flag_de = "https://wiki.opencaching.eu/images/c/c1/Oc-de.png";
|
||||
const std::string flag_us = "https://wiki.opencaching.eu/images/f/fb/Oc-us.png";
|
||||
|
@ -33,10 +35,6 @@ const std::string flag_nl = "https://wiki.opencaching.eu/images/4/4b/Oc-nl.png";
|
|||
const std::string flag_ro = "https://wiki.opencaching.eu/images/4/4f/Oc-ro.png";
|
||||
const std::string flag_uk = "https://wiki.opencaching.eu/images/5/58/Oc-org-uk.png";
|
||||
|
||||
const std::string Database_pl = "ocpl.sqlite";
|
||||
const std::string Database_de = "ocde.sqlite";
|
||||
const std::string Database_us = "ocus.sqlite";
|
||||
|
||||
void htmlencode(std::string& data);
|
||||
|
||||
void show_histogram(const Caches& cc, std::string Cache::*ptr, const std::string& caption, bool html = 0, bool sort_by_val = 1);
|
||||
|
|
28
geodb.cpp
28
geodb.cpp
|
@ -15,10 +15,8 @@ using json = nlohmann::json;
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
std::string Dump_path;
|
||||
std::string Database;
|
||||
std::string okapi_url;
|
||||
std::string okapi_key;
|
||||
bool update = 0;
|
||||
Service service = none;
|
||||
|
||||
int o;
|
||||
while ((o = getopt(argc, argv, "pdui:cD:h?")) != -1)
|
||||
|
@ -43,31 +41,25 @@ int main(int argc, char** argv) {
|
|||
update = 1;
|
||||
break;
|
||||
case 'd':
|
||||
if (!Database.empty()) {
|
||||
if (service != none) {
|
||||
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;
|
||||
service = ocde;
|
||||
break;
|
||||
case 'p':
|
||||
if (!Database.empty()) {
|
||||
if (service != none) {
|
||||
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;
|
||||
service = ocpl;
|
||||
break;
|
||||
case 'u':
|
||||
if (!Database.empty()) {
|
||||
if (service != none) {
|
||||
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;
|
||||
service = ocus;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
|
@ -84,17 +76,17 @@ int main(int argc, char** argv) {
|
|||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (Database.empty()) {
|
||||
if (service == none) {
|
||||
std::cout << "You need to specify one of the options \"-d\", \"-p\", \"-u\".\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
OCdb db(Database);
|
||||
OCdb db(service);
|
||||
if (!Dump_path.empty())
|
||||
db.init(Dump_path);
|
||||
|
||||
if (update) {
|
||||
Okapi OK(okapi_url, okapi_key);
|
||||
Okapi OK(service);
|
||||
db.update(OK);
|
||||
}
|
||||
Debug(2) << "Database now at revision: " << db.get_revision();
|
||||
|
|
152
geofriends.cpp
152
geofriends.cpp
|
@ -1,6 +1,5 @@
|
|||
#include "okapi.h"
|
||||
#include "cache.h"
|
||||
#include "debug.h"
|
||||
#include "user.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -14,34 +13,28 @@ void show_usage() {
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
#include "config_user.h"
|
||||
|
||||
if (argc < 3) show_usage();
|
||||
|
||||
std::string ocpl_user1 = argv[1];
|
||||
std::string ocpl_user2 = argv[2];
|
||||
User user1, user2;
|
||||
user1.ocpl_user = argv[1];
|
||||
user2.ocpl_user = argv[2];
|
||||
user1.use_oc = true;
|
||||
user2.use_oc = true;
|
||||
user1.get_caches();
|
||||
user2.get_caches();
|
||||
|
||||
int cc_no1 = user1.caches_hidden;
|
||||
int cc_no2 = user2.caches_hidden;
|
||||
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
std::string ocpl_user_uuid1 = OCpl.get_uuid(ocpl_user1);
|
||||
std::string ocpl_user_profile1 = OCpl.get_profile_url(ocpl_user_uuid1);
|
||||
std::string ocpl_user_uuid2 = OCpl.get_uuid(ocpl_user2);
|
||||
std::string ocpl_user_profile2 = OCpl.get_profile_url(ocpl_user_uuid2);
|
||||
Caches cc1 = OCpl.get_user_caches(ocpl_user_uuid1, 0);
|
||||
Caches cc2 = OCpl.get_user_caches(ocpl_user_uuid2, 0);
|
||||
pCaches caches_by_user1, caches_by_user2;
|
||||
|
||||
int cc_no1 = OCpl.get_user_caches_no(ocpl_user_uuid1);
|
||||
int cc_no2 = OCpl.get_user_caches_no(ocpl_user_uuid2);
|
||||
|
||||
pCaches caches_by_user1;
|
||||
pCaches caches_by_user2;
|
||||
|
||||
for (auto& i : cc2) {
|
||||
if (i.owner_uuid == ocpl_user_uuid1)
|
||||
for (auto& i : user2.cc) {
|
||||
if (i.owner_uuid == user1.ocpl_user_uuid)
|
||||
caches_by_user1.push_back(&i);
|
||||
}
|
||||
|
||||
for (auto& i : cc1) {
|
||||
if (i.owner_uuid == ocpl_user_uuid2)
|
||||
for (auto& i : user1.cc) {
|
||||
if (i.owner_uuid == user2.ocpl_user_uuid)
|
||||
caches_by_user2.push_back(&i);
|
||||
}
|
||||
|
||||
|
@ -49,72 +42,77 @@ int main(int argc, char** argv) {
|
|||
|
||||
std::cout << "<header>\n";
|
||||
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
|
||||
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile1 << "\">" << ocpl_user1 << "</a><br>\n";
|
||||
std::cout << "<img alt=\"OCpl\" src=\"https://wiki.opencaching.eu/images/b/b7/Oc-pl.png\"> <a href=\"" << ocpl_user_profile2 << "\">" << ocpl_user2 << "</a><br>\n";
|
||||
user1.header();
|
||||
user2.header();
|
||||
std::cout << "</header>\n";
|
||||
|
||||
std::cout << "<div class=\"basic_stats\">\n";
|
||||
std::cout << "Number of caches created by " << ocpl_user1 << " found by " << ocpl_user2 << ": <span class=\"value\">" << caches_by_user1.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc2.begin(), cc2.end(), [ocpl_user_uuid1](const auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid1); }) << "</span><br>\n";
|
||||
;
|
||||
std::cout << "Number of caches created by " << ocpl_user2 << " found by " << ocpl_user1 << ": <span class=\"value\">" << caches_by_user2.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(cc1.begin(), cc1.end(), [ocpl_user_uuid2](const auto& c) { return (c.recommended && c.owner_uuid == ocpl_user_uuid2); }) << "</span><br>\n";
|
||||
;
|
||||
|
||||
std::cout << "Number of caches created by " << user1.ocpl_user << " found by " << user2.ocpl_user << ": <span class=\"value\">" << caches_by_user1.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(user2.cc.begin(), user2.cc.end(), [user1](const auto& c) { return (c.recommended && c.owner_uuid == user1.ocpl_user_uuid); }) << "</span><br>\n";
|
||||
|
||||
std::cout << "Number of caches created by " << user2.ocpl_user << " found by " << user1.ocpl_user << ": <span class=\"value\">" << caches_by_user2.size() << "</span><br>\n";
|
||||
std::cout << "Number of recommendations given: <span class=\"value\">" << std::count_if(user1.cc.begin(), user1.cc.end(), [user2](const auto& c) { return (c.recommended && c.owner_uuid == user2.ocpl_user_uuid); }) << "</span><br>\n";
|
||||
|
||||
std::cout << "</div>\n";
|
||||
|
||||
// const int LIST_MAX = 100;
|
||||
short int n = 1;
|
||||
|
||||
std::cout << "<h2>Caches created by " << ocpl_user1 << " found by " << ocpl_user2 << "</h2>\n";
|
||||
std::cout << "<div class=\"histogram friendbar\">\n";
|
||||
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user1.size() / cc_no1 << "%;\"><span class=\"text\">" << 100 * caches_by_user1.size() / cc_no1 << "%</span></div>\n";
|
||||
std::cout << "</div>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto& i : caches_by_user1) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
std::cout << "<td>" << i->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
if (cc_no1 > 0) {
|
||||
std::cout << "<h2>Caches created by " << user1.ocpl_user << " found by " << user2.ocpl_user << "</h2>\n";
|
||||
std::cout << "<div class=\"histogram friendbar\">\n";
|
||||
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user1.size() / cc_no1 << "%;\"><span class=\"text\">" << 100 * caches_by_user1.size() / cc_no1 << "%</span></div>\n";
|
||||
std::cout << "</div>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
|
||||
for (auto& i : caches_by_user1) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
std::cout << "<td>" << i->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
n = 1;
|
||||
std::cout << "<h2>Caches created by " << ocpl_user2 << " found by " << ocpl_user1 << "</h2>\n";
|
||||
std::cout << "<div class=\"histogram friendbar\">\n";
|
||||
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user2.size() / cc_no2 << "%;\"><span class=\"text\">" << 100 * caches_by_user2.size() / cc_no2 << "%</span></div>\n";
|
||||
std::cout << "</div>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (auto& i : caches_by_user2) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
std::cout << "<td>" << i->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
if (cc_no2 > 0) {
|
||||
n = 1;
|
||||
std::cout << "<h2>Caches created by " << user2.ocpl_user << " found by " << user1.ocpl_user << "</h2>\n";
|
||||
std::cout << "<div class=\"histogram friendbar\">\n";
|
||||
std::cout << "<div class=\"bar\" style=\"--percent: " << 100 * caches_by_user2.size() / cc_no2 << "%;\"><span class=\"text\">" << 100 * caches_by_user2.size() / cc_no2 << "%</span></div>\n";
|
||||
std::cout << "</div>\n";
|
||||
std::cout << "<table class=\"list\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
std::cout << "<th>Cache</th>";
|
||||
std::cout << "<th>Type</th>";
|
||||
std::cout << "<th>Date hidden</th>";
|
||||
std::cout << "<th>Date found</th>";
|
||||
std::cout << "<th>Region</th>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
|
||||
for (auto& i : caches_by_user2) {
|
||||
std::cout << "<tr><th>" << n << "</th> ";
|
||||
std::cout << "<td>" << i->link_name() << "</td>";
|
||||
std::cout << "<td>" << i->type << "</td>";
|
||||
std::cout << "<td>" << i->date_hidden << "</td>";
|
||||
std::cout << "<td>" << i->date << "</td>";
|
||||
std::cout << "<td>" << i->region << "</td>";
|
||||
std::cout << "</tr>\n";
|
||||
n++;
|
||||
// if (n > LIST_MAX) break;
|
||||
}
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
|
|
12
geolist.cpp
12
geolist.cpp
|
@ -46,32 +46,32 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
if (!code_pl.empty()) {
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
Okapi OCpl(ocpl);
|
||||
Caches tmp = OCpl.get_caches(code_pl);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
if (!code_de.empty()) {
|
||||
Okapi OCde(ocde_url, ocde_key);
|
||||
Okapi OCde(ocde);
|
||||
Caches tmp = OCde.get_caches(code_de);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
if (!code_us.empty()) {
|
||||
Okapi OCus(ocus_url, ocus_key);
|
||||
Okapi OCus(ocus);
|
||||
Caches tmp = OCus.get_caches(code_us);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
if (!code_nl.empty()) {
|
||||
Okapi OCnl(ocnl_url, ocnl_key);
|
||||
Okapi OCnl(ocnl);
|
||||
Caches tmp = OCnl.get_caches(code_nl);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
if (!code_ro.empty()) {
|
||||
Okapi OCro(ocro_url, ocro_key);
|
||||
Okapi OCro(ocro);
|
||||
Caches tmp = OCro.get_caches(code_ro);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
if (!code_uk.empty()) {
|
||||
Okapi OCuk(ocuk_url, ocuk_key);
|
||||
Okapi OCuk(ocuk);
|
||||
Caches tmp = OCuk.get_caches(code_uk);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
}
|
||||
|
|
|
@ -161,6 +161,9 @@ int main(int argc, char** argv) {
|
|||
user.prepare_lists_of_caches();
|
||||
|
||||
header_html();
|
||||
|
||||
std::cout << "<header>\n";
|
||||
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
|
||||
user.header();
|
||||
|
||||
if (user.time_filter) {
|
||||
|
|
16
ocdb.cpp
16
ocdb.cpp
|
@ -11,10 +11,22 @@
|
|||
using json = nlohmann::json;
|
||||
// using namespace std::literals::string_literals;
|
||||
|
||||
OCdb::OCdb(const std::string& db_file) {
|
||||
OCdb::OCdb(const Service service) {
|
||||
int res = 0;
|
||||
|
||||
res = sqlite3_open(db_file.c_str(), &db);
|
||||
switch (service) {
|
||||
case ocpl:
|
||||
res = sqlite3_open(Database_pl, &db);
|
||||
break;
|
||||
case ocde:
|
||||
res = sqlite3_open(Database_de, &db);
|
||||
break;
|
||||
case ocus:
|
||||
res = sqlite3_open(Database_us, &db);
|
||||
default:
|
||||
throw 1;
|
||||
}
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << sqlite3_errmsg(db);
|
||||
throw 1;
|
||||
|
|
6
ocdb.h
6
ocdb.h
|
@ -34,8 +34,12 @@ private:
|
|||
other = -1
|
||||
};
|
||||
|
||||
constexpr static auto Database_pl = "ocpl.sqlite";
|
||||
constexpr static auto Database_de = "ocde.sqlite";
|
||||
constexpr static auto Database_us = "ocus.sqlite";
|
||||
|
||||
public:
|
||||
explicit OCdb(const std::string& db_file);
|
||||
explicit OCdb(const Service service);
|
||||
~OCdb();
|
||||
|
||||
bool init(const std::string& dump_path); // read db dump
|
||||
|
|
46
okapi.cpp
46
okapi.cpp
|
@ -11,19 +11,37 @@
|
|||
|
||||
using json = nlohmann::json;
|
||||
|
||||
Okapi::Okapi(const std::string& server_url, const std::string& consumer_key) : url(server_url), key(consumer_key) {
|
||||
if (url.find(".pl/") != std::string::npos)
|
||||
service = "OC.pl";
|
||||
if (url.find(".de/") != std::string::npos)
|
||||
service = "OC.de";
|
||||
if (url.find(".us/") != std::string::npos)
|
||||
service = "OC.us";
|
||||
if (url.find(".nl/") != std::string::npos)
|
||||
service = "OC.nl";
|
||||
if (url.find(".ro/") != std::string::npos)
|
||||
service = "OC.ro";
|
||||
if (url.find(".uk/") != std::string::npos)
|
||||
service = "OC.uk";
|
||||
Okapi::Okapi(const Service serv) : service(serv) {
|
||||
#include "config_user.h"
|
||||
|
||||
switch (serv) {
|
||||
case ocpl:
|
||||
url = ocpl_url;
|
||||
key = ocpl_key;
|
||||
break;
|
||||
case ocde:
|
||||
url = ocde_url;
|
||||
key = ocde_key;
|
||||
break;
|
||||
case ocus:
|
||||
url = ocus_url;
|
||||
key = ocus_key;
|
||||
break;
|
||||
case ocnl:
|
||||
url = ocnl_url;
|
||||
key = ocnl_key;
|
||||
break;
|
||||
case ocro:
|
||||
url = ocro_url;
|
||||
key = ocro_key;
|
||||
break;
|
||||
case ocuk:
|
||||
url = ocuk_url;
|
||||
key = ocuk_key;
|
||||
break;
|
||||
case none:
|
||||
throw 1;
|
||||
}
|
||||
|
||||
curl = curl_easy_init();
|
||||
if (!curl) {
|
||||
|
@ -253,7 +271,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
|
|||
return cc;
|
||||
}
|
||||
|
||||
int Okapi::get_user_caches_no(const std::string& uuid) const {
|
||||
int Okapi::get_user_hidden_caches_no(const std::string& uuid) const {
|
||||
std::string api_service = url + OKAPI_user;
|
||||
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=caches_hidden";
|
||||
curl_post(api_service, query);
|
||||
|
|
15
okapi.h
15
okapi.h
|
@ -3,7 +3,7 @@
|
|||
#include "api.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
typedef void CURL;
|
||||
|
@ -13,7 +13,7 @@ private:
|
|||
std::string url;
|
||||
std::string key;
|
||||
|
||||
std::string service;
|
||||
Service service;
|
||||
|
||||
CURL* curl;
|
||||
mutable std::string curl_output;
|
||||
|
@ -35,14 +35,21 @@ private:
|
|||
constexpr static auto OKAPI_user = "services/users/user";
|
||||
constexpr static auto OKAPI_changelog = "services/replicate/changelog";
|
||||
|
||||
constexpr static auto ocpl_url = "https://opencaching.pl/okapi/";
|
||||
constexpr static auto ocde_url = "https://www.opencaching.de/okapi/";
|
||||
constexpr static auto ocus_url = "http://www.opencaching.us/okapi/";
|
||||
constexpr static auto ocnl_url = "http://www.opencaching.nl/okapi/";
|
||||
constexpr static auto ocro_url = "http://www.opencaching.ro/okapi/";
|
||||
constexpr static auto ocuk_url = "https://opencache.uk/okapi/";
|
||||
|
||||
public:
|
||||
Okapi(const std::string& server_url, const std::string& consumer_key);
|
||||
Okapi(const Service serv);
|
||||
~Okapi();
|
||||
|
||||
// Cache get_cache(std::string code);
|
||||
Caches get_caches(const std::set<std::string>& codes) const;
|
||||
Caches get_user_caches(const std::string& uuid, int count = 0) const override;
|
||||
int get_user_caches_no(const std::string& uuid) const;
|
||||
int get_user_hidden_caches_no(const std::string& uuid) const;
|
||||
std::string get_changelog_json(int revision) const;
|
||||
|
||||
void update_caches(Caches& cc) const;
|
||||
|
|
32
user.cpp
32
user.cpp
|
@ -5,11 +5,10 @@
|
|||
#include "debug.h"
|
||||
|
||||
void User::get_caches() {
|
||||
#include "config_user.h"
|
||||
|
||||
if (use_oc) {
|
||||
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
Okapi OCpl(ocpl);
|
||||
uint uid;
|
||||
if (!ocpl_user.empty()) ocpl_user_uuid = OCpl.get_uuid(ocpl_user, &uid);
|
||||
Caches tmp = OCpl.get_user_caches(ocpl_user_uuid, 0);
|
||||
|
@ -39,40 +38,41 @@ void User::get_caches() {
|
|||
std::sort(tt.begin(), tt.end(), [&](const auto& a, const auto& b) { return a->completed_perc > b->completed_perc; });
|
||||
|
||||
OCpl.get_ftf(uid, tmp);
|
||||
caches_hidden = OCpl.get_user_hidden_caches_no(ocpl_user_uuid);
|
||||
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid);
|
||||
}
|
||||
if (!ocde_user_uuid.empty() || !ocde_user.empty()) {
|
||||
Okapi OCde(ocde_url, ocde_key);
|
||||
Okapi OCde(ocde);
|
||||
if (!ocde_user.empty()) ocde_user_uuid = OCde.get_uuid(ocde_user);
|
||||
Caches tmp = OCde.get_user_caches(ocde_user_uuid, 0);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
ocde_user_profile = OCde.get_profile_url(ocde_user_uuid);
|
||||
}
|
||||
if (!ocus_user_uuid.empty() || !ocus_user.empty()) {
|
||||
Okapi OCus(ocus_url, ocus_key);
|
||||
Okapi OCus(ocus);
|
||||
if (!ocus_user.empty()) ocus_user_uuid = OCus.get_uuid(ocus_user);
|
||||
Caches tmp = OCus.get_user_caches(ocus_user_uuid, 0);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
ocus_user_profile = OCus.get_profile_url(ocus_user_uuid);
|
||||
}
|
||||
if (!ocnl_user_uuid.empty() || !ocnl_user.empty()) {
|
||||
Okapi OCnl(ocnl_url, ocnl_key);
|
||||
Okapi OCnl(ocnl);
|
||||
if (!ocnl_user.empty()) ocnl_user_uuid = OCnl.get_uuid(ocnl_user);
|
||||
Caches tmp = OCnl.get_user_caches(ocnl_user_uuid, 0);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
ocnl_user_profile = OCnl.get_profile_url(ocnl_user_uuid);
|
||||
}
|
||||
if (!ocro_user_uuid.empty() || !ocro_user.empty()) {
|
||||
Okapi OCro(ocro_url, ocro_key);
|
||||
Okapi OCro(ocro);
|
||||
if (!ocro_user.empty()) ocro_user_uuid = OCro.get_uuid(ocro_user);
|
||||
Caches tmp = OCro.get_user_caches(ocro_user_uuid, 0);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
ocro_user_profile = OCro.get_profile_url(ocro_user_uuid);
|
||||
}
|
||||
if (!ocuk_user_uuid.empty() || !ocuk_user.empty()) {
|
||||
Okapi OCuk(ocuk_url, ocuk_key);
|
||||
Okapi OCuk(ocuk);
|
||||
if (!ocuk_user.empty()) ocuk_user_uuid = OCuk.get_uuid(ocuk_user);
|
||||
Caches tmp = OCuk.get_user_caches(ocuk_user_uuid, 0);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
|
@ -88,21 +88,21 @@ void User::get_caches() {
|
|||
|
||||
if (use_ocdb) {
|
||||
if (!ocpl_user_uuid.empty() || !ocpl_user.empty()) {
|
||||
OCdb db(Database_pl);
|
||||
OCdb db(ocpl);
|
||||
if (!ocpl_user.empty()) {
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
Okapi OCpl(ocpl);
|
||||
ocpl_user_uuid = OCpl.get_uuid(ocpl_user);
|
||||
ocpl_user_profile = OCpl.get_profile_url(ocpl_user_uuid);
|
||||
}
|
||||
if (get_not_found) {
|
||||
Caches tmp = db.get_user_caches_not_found(ocpl_user_uuid);
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
Okapi OCpl(ocpl);
|
||||
OCpl.update_caches(tmp);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
region_count = db.get_region_stats();
|
||||
} else if (get_owned) {
|
||||
Caches tmp = db.get_user_caches_owned(ocpl_user_uuid);
|
||||
Okapi OCpl(ocpl_url, ocpl_key);
|
||||
Okapi OCpl(ocpl);
|
||||
OCpl.update_caches(tmp);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
} else {
|
||||
|
@ -111,21 +111,21 @@ void User::get_caches() {
|
|||
}
|
||||
}
|
||||
if (!ocde_user_uuid.empty() || !ocde_user.empty()) {
|
||||
OCdb db(Database_de);
|
||||
OCdb db(ocde);
|
||||
if (!ocde_user.empty()) {
|
||||
Okapi OCde(ocde_url, ocde_key);
|
||||
Okapi OCde(ocde);
|
||||
ocde_user_uuid = OCde.get_uuid(ocde_user);
|
||||
ocde_user_profile = OCde.get_profile_url(ocde_user_uuid);
|
||||
}
|
||||
if (get_not_found) {
|
||||
Caches tmp = db.get_user_caches_not_found(ocde_user_uuid);
|
||||
Okapi OCde(ocde_url, ocde_key);
|
||||
Okapi OCde(ocde);
|
||||
OCde.update_caches(tmp);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
// region_count = db.get_region_stats();
|
||||
} else if (get_owned) {
|
||||
Caches tmp = db.get_user_caches_owned(ocde_user_uuid);
|
||||
Okapi OCde(ocde_url, ocde_key);
|
||||
Okapi OCde(ocde);
|
||||
OCde.update_caches(tmp);
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(cc));
|
||||
} else {
|
||||
|
@ -199,8 +199,6 @@ void User::prepare_lists_of_caches() {
|
|||
}
|
||||
|
||||
void User::header() {
|
||||
std::cout << "<header>\n";
|
||||
std::cout << "<h1><a href=\"/geo\">Geocaching stats</a> for user profiles:</h1>\n";
|
||||
if (!ocpl_user.empty())
|
||||
std::cout << "<img alt=\"OCpl\" src=\"" << flag_pl << "\"> <a href=\"" << ocpl_user_profile << "\">" << ocpl_user << "</a><br>\n";
|
||||
if (!ocde_user.empty())
|
||||
|
|
29
user.h
29
user.h
|
@ -12,14 +12,21 @@ private:
|
|||
PowertrailDB traildb;
|
||||
Caches_in_Powertrails tc;
|
||||
|
||||
std::string ocpl_user_profile;
|
||||
std::string ocde_user_profile;
|
||||
std::string ocus_user_profile;
|
||||
std::string ocnl_user_profile;
|
||||
std::string ocro_user_profile;
|
||||
std::string ocuk_user_profile;
|
||||
|
||||
public:
|
||||
// Position home;
|
||||
std::string ocpl_user_uuid = "";
|
||||
std::string ocde_user_uuid = "";
|
||||
std::string ocus_user_uuid = "";
|
||||
std::string ocnl_user_uuid = "";
|
||||
std::string ocro_user_uuid = "";
|
||||
std::string ocuk_user_uuid = "";
|
||||
std::string ocpl_user_uuid;
|
||||
std::string ocde_user_uuid;
|
||||
std::string ocus_user_uuid;
|
||||
std::string ocnl_user_uuid;
|
||||
std::string ocro_user_uuid;
|
||||
std::string ocuk_user_uuid;
|
||||
|
||||
bool use_oc = 0;
|
||||
bool use_ocdb = 0;
|
||||
|
@ -31,13 +38,6 @@ public:
|
|||
std::string ocuk_user;
|
||||
// std::string gpx_file;
|
||||
|
||||
std::string ocpl_user_profile;
|
||||
std::string ocde_user_profile;
|
||||
std::string ocus_user_profile;
|
||||
std::string ocnl_user_profile;
|
||||
std::string ocro_user_profile;
|
||||
std::string ocuk_user_profile;
|
||||
|
||||
bool get_not_found = 0;
|
||||
bool get_owned = 0;
|
||||
bool exclude_quiz = 0;
|
||||
|
@ -46,7 +46,8 @@ public:
|
|||
bool time_filter = 0;
|
||||
|
||||
Caches cc;
|
||||
int caches_count;
|
||||
int caches_count = 0;
|
||||
int caches_hidden = 0;
|
||||
std::map<std::string, int> dates;
|
||||
Date_Caches sorted_caches;
|
||||
Date_Caches sorted_fcaches;
|
||||
|
|
Ładowanie…
Reference in New Issue