Fetch cache status

sql-rework
Tomasz Golinski 2020-03-06 10:55:57 +01:00
rodzic 6e6330975f
commit 8edb4893f0
3 zmienionych plików z 28 dodań i 2 usunięć

Wyświetl plik

@ -11,7 +11,16 @@ static float degtorad(float x) {
}
void Cache::show() const {
std::cout << "Cache:\t" << code << ' ' << name << " (type: " << type << ", owned by " << owner << ")\n";
std::cout << "Cache:\t" << code << ' ' << name << " (";
if (status == ok)
std::cout << "OK";
else if (status == disabled)
std::cout << "DIS";
else if (status == archived)
std::cout << "ARCH";
else
std::cout << "UNK";
std::cout << " type: " << type << ", owned by " << owner << ")\n";
std::cout << '\t' << pos.lat << " " << pos.lon << "\t\tD/T: " << diff << '/' << terr << "\t\tSize: " << size << "\t\tFound on " << date << '\n';
}

Wyświetl plik

@ -31,6 +31,13 @@
// podcast //a geocache with attached MP3 file(s). The MP3 data is not accessible via OKAPI. This type is only in use at Opencaching.US
// };
enum Status {
ok, // available
disabled, // temporarily disabled
archived, // archived
unknown
};
const int Earth_radius = 6378;
const double Pi = 3.14159265358979323846264338327950288;
@ -48,6 +55,7 @@ public:
std::string code;
Position pos;
std::string name;
Status status;
std::string size;
float diff = 0;
float terr = 0;

Wyświetl plik

@ -90,7 +90,7 @@ std::string Okapi::get_user_caches_json(const std::string& uuid, int count, int
std::string Okapi::get_caches_json(const std::string& codes) const {
std::string service = url + OKAPI_caches;
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|size2|date_hidden|recommendations|founds";
std::string query = "consumer_key=" + key + "&cache_codes=" + codes + "&fields=code|name|location|type|status|difficulty|terrain|owner|region|size2|date_hidden|recommendations|founds|status";
return curl_post(service, query);
}
@ -156,6 +156,15 @@ Caches Okapi::get_caches(const std::set<std::string>& codes) const {
c.fav = el.value()["recommendations"];
c.founds = el.value()["founds"];
if (el.value()["status"] == "Available")
c.status = ok;
else if (el.value()["status"] == "Temporarily unavailable")
c.status = disabled;
else if (el.value()["status"] == "Archived")
c.status = archived;
else
c.status = unknown;
std::tm tmp;
std::stringstream ss(el.value()["date_hidden"].get<std::string>());
ss >> std::get_time(&tmp, "%Y-%m-%dT%H:%M:%S+");