Grab more data about powertrails (type, active caches)

master
Tomasz Golinski 2022-07-18 19:36:46 +02:00
rodzic 637a637626
commit 6706ef9898
2 zmienionych plików z 36 dodań i 3 usunięć

Wyświetl plik

@ -15,19 +15,22 @@ static const std::string url = "https://opencaching.pl/powerTrail.php?ptAction=s
static const std::string url2 = "https://opencaching.pl/powerTrail/ajaxGetPowerTrailCaches.php?ptAction=showSerie&ptrail=";
static const std::regex regex_name("<span id=\"powerTrailName\">(.*?)</span>");
static const std::regex regex_type("<span id=\"ptTypeName\">(.*?)</span>");
static const std::regex regex_date("<span id=\"powerTrailDateCreated\">(.*?)</span>");
static const std::regex regex_perc("<span id=\"powerTrailpercent\">(.*?)</span>");
static const std::regex regex_cache("<a href=\"(OP.*?)\">");
static const std::regex regex_cache("<a href=\"(OP.*?)\">.*?<img src=\"/images/log/(.*?)\\.png\"");
void to_json(json& j, const Powertrail& item) {
j = json{ { "name", item.name }, { "date", item.date_str }, { "treshold", item.treshold_perc }, { "caches", item.caches } };
j = json{ { "name", item.name }, { "date", item.date_str }, { "treshold", item.treshold_perc }, { "active", item.active_caches }, { "caches", item.caches }, { "type", item.type } };
}
void from_json(const json& j, Powertrail& item) {
j.at("name").get_to(item.name);
j.at("date").get_to(item.date_str);
j.at("treshold").get_to(item.treshold_perc);
j.at("active").get_to(item.active_caches);
j.at("caches").get_to(item.caches);
j.at("type").get_to(item.type);
strptime(item.date_str.c_str(), "%d-%m-%Y", &item.date);
}
@ -44,6 +47,9 @@ std::string Powertrail::safe_name() const {
htmlencode(tmp);
return tmp;
}
std::string Powertrail::get_type() const {
return types[type];
}
PowertrailDB::PowertrailDB() {
curl = curl_easy_init();
@ -83,6 +89,18 @@ void PowertrailDB::get_trail(uint n) {
Debug(2) << "Read name: " << T.name;
} else
return;
if (std::regex_search(curl_output, res, regex_type) && res.size() == 2) {
if (res[1].str() == "Geo-szkic")
T.type = geoszkic;
else if (res[1].str() == "Krajoznawcza")
T.type = krajoznawcza;
else if (res[1].str() == "Przyrodnicza")
T.type = przyrodnicza;
else if (res[1].str() == "Tematyczna")
T.type = tematyczna;
else
T.type = unknown_type;
}
if (std::regex_search(curl_output, res, regex_date) && res.size() == 2) {
strptime(res[1].str().c_str(), "%d-%m-%Y", &T.date);
T.date_str = res[1].str();
@ -110,7 +128,8 @@ void PowertrailDB::get_trail(uint n) {
for (std::sregex_iterator i = caches_begin; i != caches_end; i++) {
std::smatch match = *i;
T.caches.insert(match[1].str());
// Debug(2) << match[1].str();
if (match[2].str() == "16x16-published")
T.active_caches++;
}
data.insert({ n, T });

Wyświetl plik

@ -11,21 +11,35 @@
typedef void CURL;
class Caches_in_Powertrails;
enum Powertrail_Type {
geoszkic,
krajoznawcza,
przyrodnicza,
tematyczna,
unknown_type
};
class Powertrail {
public:
uint number;
std::string name;
Powertrail_Type type = unknown_type;
std::tm date;
std::string date_str;
uint treshold_perc;
std::unordered_set<std::string> caches;
uint active_caches = 0;
uint found = 0;
bool completed = 0;
std::string link() const;
std::string link_name() const;
std::string safe_name() const;
std::string get_type() const;
inline static const std::string types[] = { "geo-szkic", "krajoznawcza", "przyrodnicza", "tematyczna", "nieznany" };
};
class PowertrailDB {