Author Topic: Converting an old script to the new weather.gov API  (Read 615 times)

0 Members and 1 Guest are viewing this topic.

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Converting an old script to the new weather.gov API
« on: May 20, 2019, 11:18:03 AM »
This should be relatively easy but I keep getting stuck.  This code uses the old https://forecast.weather.gov/MapClick.php method of retrieving a local forecast.  How would I properly change this code to utilize the new weather.gov API?

Code: [Select]
<form action="https://forecast.weather.gov/zipcity.php" method="post">
        <fieldset>
        <legend><br /><label for="zipcity">Choose a location and enter it in the box below, then click SEARCH</label></legend>
        </fieldset>
        <br />
        <input  type="text" id="zipcity" name="inputstring" value="City or Zip Code"  onfocus="this.value=''" />&nbsp;&nbsp;
        <input style="font-size:14px;" type="submit" name="" value="Search" />
</form>


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Converting an old script to the new weather.gov API
« Reply #1 on: May 20, 2019, 11:45:35 AM »
I'm not seeing an equivalent function in the weather.gov API

Since forecast-v3.weather.gov does have a 'search' capability, there is likely a way to do it, but it's just not documented about how to do it via the API itself.

The 'search' area on the page has some code
Code: [Select]
               <form name="getForecast" id="getForecast" class="form-inline" action="/point" method="get">
    <div id="getfcst-body">
        <div id="loc-search-block">
            <input id="searchInput" name="q" type="text" class="form-control" placeholder="Location or Zip Code" autocomplete="off">
            <input id="btnSearch" name="" class="btn btn-default" type="submit" value="Go">
        </div>
        <div id="txtHelp" class="row">
            <a href="javascript:void(window.open('/bundles/noaatemplating/static/searchHelp.html?7958d2e','locsearchhelp','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=530').focus());">
                View Location Examples
            </a>
        </div>
    </div>
    <div id="searchOptions" class="hidden">
        <div id="useCurrent" class="search_option current_location">Use My Current Location</div>
        <div id="searchResults">
            <div id="searchResultsService" class="search_block hidden">
                <div class="search_option search_heading">Search Results</div>
                <div class="search_content"><div class="autocomplete-suggestions" style="position: absolute; display: none; max-height: 159px; z-index: 9999;"></div></div>
            </div>
            <div id="searchResultsHistory" class="search_block">
                <div class="search_option search_heading">Recent Searches</div>
                <div class="search_content"><div class="search_option saved_location">Cedar Rapids, Iowa</div><div class="search_option saved_location">Lufkin, Texas</div><div class="search_option saved_location">Minden, Texas</div><div class="search_option saved_location">Baldwin, Alabama</div><div class="search_option saved_location">Saratoga, California</div></div>
            </div>
            <div id="searchResultsMessage" class="search_block hidden">
                <div class="search_option search_heading">Notification</div>
                <div class="search_content"></div>
            </div>
        </div>
    </div>
</form>
and is driven by JavaScript to do the listings/updates, likely with some currently undocumented query.

We've got a few months yet before the old www.weather.gov is cycled to the new format.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: Converting an old script to the new weather.gov API
« Reply #2 on: May 20, 2019, 11:58:24 AM »
Thanks Ken.  I thought I was missing something because nothing I tried would work!

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: Converting an old script to the new weather.gov API
« Reply #3 on: May 20, 2019, 12:31:10 PM »
The closest I've been able to approximate this makes use of a file that converts zip codes to lat/long points.

https://github.com/jalbertbowden/us-data/tree/master/civicspace-zip-code-database

From that file, I generated a (big) PHP table indexed by zip code.  With the lat and long, a useful query can then be constructed to get meta data (forecast zone and NWS office) as well as the forecast.

I have code based on this running in my sandbox (not on my live site). Essentially I allow a "zip" URL parameter on the forecast page and monkey around with the variables that advforecast2 uses before including it.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: Converting an old script to the new weather.gov API
« Reply #4 on: May 20, 2019, 01:53:06 PM »
Ken,  I forwarded a response I got from the NWS on this issue to your webmaster email box.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Converting an old script to the new weather.gov API
« Reply #5 on: May 20, 2019, 06:01:56 PM »
Thanks,  I saw the reply .. it doesn't address the search capability (which is not in the current API per se).. the function of MapClick.php to provide a forecast is replaced by a series of API calls (point, gridpoint), but that doesn't provide the search using 'zipcity.php' on their site.. the https://www.weather.gov/documentation/ docs don't mention 'zipcity.php' as a function, so we won't know if it exists in the future.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything