]> Pileus Git - aweather/commitdiff
conus update conus-update
authorAndy Spencer <andy753421@gmail.com>
Wed, 10 Nov 2021 05:18:39 +0000 (05:18 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 10 Nov 2021 05:18:39 +0000 (05:18 +0000)
src/plugins/radar.c

index 50c66a8bab19011a77949951a206e70563a7fc62..6958cef969c6341abd55e7a8632c0d7c1bc3412c 100644 (file)
@@ -51,9 +51,9 @@ static gchar *_find_nearest(time_t time, GList *files,
        struct tm tm = {};
        for (GList *cur = files; cur; cur = cur->next) {
                gchar *file = cur->data;
-               sscanf(file+offset, "%4d%2d%2d_%2d%2d",
+               sscanf(file+offset, "%4d%2d%2d_%2d%2d%2d",
                                &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-                               &tm.tm_hour, &tm.tm_min);
+                               &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
                tm.tm_year -= 1900;
                tm.tm_mon  -= 1;
                if (ABS(time - mktime(&tm)) <
@@ -156,7 +156,7 @@ gpointer _site_update_thread(gpointer _site)
        gchar *dir_list = g_strconcat(nexrad_url, "/", site->city->code,
                        "/", "dir.list", NULL);
        GList *files = grits_http_available(site->http,
-                       "^\\w{4}_\\d{8}_\\d{4}$", site->city->code,
+                       "^\\w{4}_\\d{8}_\\d{4}(\\d{2}\\.bz2)?$", site->city->code,
                        "\\d+ (.*)", (offline ? NULL : dir_list));
        g_free(dir_list);
        gchar *nearest = _find_nearest(site->time, files, 5);
@@ -520,23 +520,22 @@ gpointer _conus_update_thread(gpointer _conus)
        /* Find nearest */
        g_debug("Conus: update_thread - nearest");
        gboolean offline = grits_viewer_get_offline(conus->viewer);
-       gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
+       gchar *conus_url = "https://mesonet.agron.iastate.edu/archive/data/";
        gchar *nearest;
-       if (time(NULL) - conus->time < 60*60*5 && !offline) {
-               /* radar.weather.gov is full of lies.
-                * the index pages get cached and out of date */
-               /* gmtime is not thread safe, but it's not used very often so
-                * hopefully it'll be alright for now... :-( */
-               struct tm *tm = gmtime(&conus->time);
-               time_t onthe8 = conus->time - 60*((tm->tm_min+1)%10+1);
-               tm = gmtime(&onthe8);
-               nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif",
-                               tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
-                               tm->tm_hour, tm->tm_min);
+       if (!offline) {
+               struct tm tm;
+               gmtime_r(&conus->time, &tm);
+               time_t onthe8 = conus->time - 60*(tm.tm_min%5);
+               gmtime_r(&onthe8, &tm);
+               nearest = g_strdup_printf("%04d/%02d/%02d/GIS/uscomp/"
+                                         "n0q_%04d%02d%02d%02d%02d.png",
+                               tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
+                               tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
+                               tm.tm_hour, tm.tm_min);
        } else {
                GList *files = grits_http_available(conus->http,
-                               "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL);
-               nearest = _find_nearest(conus->time, files, 6);
+                               "^n0q_[^\"]*.png$", "", NULL, NULL);
+               nearest = _find_nearest(conus->time, files, 4);
                g_list_foreach(files, (GFunc)g_free, NULL);
                g_list_free(files);
                if (!nearest) {