diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-17 23:25:10 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-17 23:25:10 -0700 |
commit | dd9811703ad623e6b3ddc51e58ef5cc801f41951 (patch) | |
tree | 7c10fbd421919cbf2ff19fd3454445790102e6c1 /src/invapi.cpp | |
parent | 8b4fa2a3b6b1a3d75fd4ae5a61266e159d22e095 (diff) | |
download | ytcpp-dd9811703ad623e6b3ddc51e58ef5cc801f41951.tar.gz |
save to db is working
Diffstat (limited to 'src/invapi.cpp')
-rw-r--r-- | src/invapi.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/invapi.cpp b/src/invapi.cpp index 59e91bf..f53c06b 100644 --- a/src/invapi.cpp +++ b/src/invapi.cpp @@ -22,7 +22,7 @@ vector<string> InvidiousApi::getInstances() { vector<string> result; cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, - cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api"}}, + cpr::Parameters{{"sort_by", "health"}}, cpr::Timeout{5000}); if (r.status_code > 299) { @@ -44,7 +44,7 @@ vector<string> InvidiousApi::getInstances() { void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) { cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, - cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api,health,location"}}, + cpr::Parameters{{"sort_by", "health"}}, cpr::Timeout{5000}); if (r.status_code > 299) { @@ -55,9 +55,17 @@ void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) { json j = json::parse(r.text); for ( json i: j ) { - if ( i.at(1).at("api") != json::value_t::null && i.at(1).at("api")) { - - sqldb.saveInstance(i[1]["uri"], i[1]["health"], i[1]["location"]); + if ( i.at(1).at("api") != json::value_t::null && i.at(1).at("api") + && i.at(1).at("monitor") != json::value_t::null + && i.at(1).at("monitor").at("30dRatio") != json::value_t::null + && i.at(1).at("monitor").at("30dRatio").at("ratio") != json::value_t::null + && i.at(1).at("uri") != json::value_t::null + && i.at(1).at("region") != json::value_t::null) { + + string uri = i[1]["uri"]; + string health = i[1]["monitor"]["30dRatio"]["ratio"]; + string region = i[1]["region"]; + sqldb.saveInstance(uri.c_str(), stof(health), region.c_str()); } } } |