summaryrefslogtreecommitdiff
path: root/src/localtemp.cpp
diff options
context:
space:
mode:
authorketsuban_152 <webmaster@dangofacotry.net>2026-08-09 12:46:24 +0900
committerketsuban_152 <webmaster@dangofacotry.net>2026-08-09 12:46:24 +0900
commit79b865963401242bfa9eaaa29efab781856bbac1 (patch)
tree0591e26901f85798d88d83596e82ecfe93c3d9bd /src/localtemp.cpp
parent6cc8243218edbee7a56a17f4f2513edfcf350738 (diff)
downloaddwgo-79b865963401242bfa9eaaa29efab781856bbac1.tar.gz
dwgo-79b865963401242bfa9eaaa29efab781856bbac1.tar.bz2
dwgo-79b865963401242bfa9eaaa29efab781856bbac1.zip
deleted: src/Team Git Repository
deleted: src/basic modified: src/localtemp.cpp modified: src/localtemp.h deleted: src/valid-user
Diffstat (limited to 'src/localtemp.cpp')
-rw-r--r--src/localtemp.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/localtemp.cpp b/src/localtemp.cpp
index 7f20dc7..a1b212e 100644
--- a/src/localtemp.cpp
+++ b/src/localtemp.cpp
@@ -140,7 +140,7 @@ void localtemp::get_ob_info(double precip10m)
{
mInfo.rain=undef_rain;
mInfo.sky=clear;
- }
+ }
// The most important for the display theme is rain, then fog and then sky conditions
if (mInfo.rain!=undef_rain)
@@ -232,11 +232,14 @@ bool localtemp::extract_json_number(const string &json, const string &key, doubl
* Date Author Modification *
* *
*************************************************************/
-bool localtemp::fetch_latest_time(string &yyyymmdd, string &hhmm, time_t &obs_utc)
+bool localtemp::fetch_latest_time(string &yyyymmdd, string &hhmmss, string &block3h, time_t &obs_utc)
{
MySock *skt;
HTTP_Request *http;
struct tm jst;
+ int hour, block;
+ char blockbuf[3];
+
skt = new MySock((char*)AMEDAS_LATEST_URL);
http=skt->GetHTTPData();
delete skt;
@@ -245,12 +248,17 @@ bool localtemp::fetch_latest_time(string &yyyymmdd, string &hhmm, time_t &obs_ut
// Expected format: YYYY-MM-DDTHH:MM:SS+09:00
string d=http->data;
yyyymmdd=d.substr(0,4)+d.substr(5,2)+d.substr(8,2);
- hhmm=d.substr(11,2)+d.substr(14,2);
+ hhmmss=d.substr(11,2)+d.substr(14,2)+d.substr(17,2);
+ hour=atoi(d.substr(11,2).data());
+ block=(hour/3)*3; // Point files are split into 3 hour windows: 00,03,06,...,21
+ sprintf(blockbuf, "%02d", block);
+ block3h=blockbuf;
+
memset(&jst, 0, sizeof(jst));
jst.tm_year=atoi(d.substr(0,4).data())-1900;
jst.tm_mon =atoi(d.substr(5,2).data())-1;
jst.tm_mday=atoi(d.substr(8,2).data());
- jst.tm_hour=atoi(d.substr(11,2).data());
+ jst.tm_hour=hour;
jst.tm_min =atoi(d.substr(14,2).data());
jst.tm_sec =atoi(d.substr(17,2).data());
obs_utc=timegm(&jst)-9*3600; // JST -> UTC (JMA has no DST, always UTC+9)
@@ -275,18 +283,19 @@ bool localtemp::getInfo()
char *point_fetch; // Amedas point data URL
MySock *skt;
HTTP_Request *http;
- string yyyymmdd, hhmm;
+ string yyyymmdd, hhmmss, block3h;
time_t obs_utc;
double temp_c, hum, precip10m;
this->error=0; // No error
this->loaded=false;
- if (!fetch_latest_time(yyyymmdd, hhmm, obs_utc))
- return false;
- point_fetch= (char*) malloc(strlen(AMEDAS_POINT_URL)+this->metar.length()+yyyymmdd.length()+4);
- sprintf(point_fetch, AMEDAS_POINT_URL, this->metar.data(), yyyymmdd.data());
-
+ if (!fetch_latest_time(yyyymmdd, hhmmss, block3h, obs_utc))
+ return false;
+
+ point_fetch= (char*) malloc(strlen(AMEDAS_POINT_URL)+this->metar.length()+yyyymmdd.length()+block3h.length()+4);
+ sprintf(point_fetch, AMEDAS_POINT_URL, this->metar.data(), yyyymmdd.data(), block3h.data());
+
skt = new MySock(point_fetch);
verbsth(VERB_ASTTO, "Open connection: ");
@@ -304,11 +313,10 @@ bool localtemp::getInfo()
verbsth(VERB_ASTTO, "Get Data: ");
this->long_location=this->location_name;
- // Locate the "HHMM": { ... } block matching the latest
- // reported observation time and keep it (and everything
- // after it, it doesn't matter) in this->ob, mirroring the
- // way the old METAR "ob:" line used to be stored.
- size_t blockpos=http->data.find("\""+hhmm+"\":");
+
+ string fullkey=yyyymmdd+hhmmss;
+ size_t blockpos=http->data.find("\""+fullkey+"\":");
+
if (blockpos==string::npos)
{
blockpos=http->data.rfind("\":{");