forked from rpringle/National-Weather-Service-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
mrcoulson/National-Weather-Service-Parser
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The National Weather Service Parser (NWS Parser) was created for local and state governments or anyone else who wishes to display the local weather on a website without any branding or forced display styles that are typical of third party weather widgets. This code will parse an XML feed of your choosing from the National Weather Service, write it locally, and then display the resulting data on a web page. The user only needs to supply the name of the XML feed that represents the nearest NWS weather station, and the name for the local copy. This code requires PHP 5.0.9 or later and/or support for PHP's SimpleXML. It is implemented as a function that returns an XML array of variables. The user can choose which elements to display and how to display them. Sample display files are also included for your use. This code is licensed under the two clause BSD license. See http://opensource.org/licenses/BSD-2-clause. SETUP INSTRUCTIONS 1. Download and install Weather icons In order to reduce the load on the National Weather Service (NWS) servers, it is recommended that you download the NWS weather icons pack and install them locally on your own server. The icons can be downloaded directly from: http://www.weather.gov/images/weather/fcicons/Weather%20Icons.zip The default installation location is "/images/weather/." If you choose a different location, please be sure to update the $iconspath variable with the correct location. A complete overview of the icons can be found here: http://www.weather.gov/xml/current_obs/weather.php You can also design your own weather icons. As long as they retain the same file names, they will work just fine with the NWS Parser function. 2. Setup local feeds directory By default, NWS Parser is set to write a copy of the NWS XML feed you choose to a directory called "feeds." You need to create this directory at the root of your server (or define your own alternative directory) and make sure it has proper permissions. The directory should be chmodded to '755' to allow the XML file to be written. 3. Define variables There are three user configurable variables: A. $localfeed - This is the file name/path that you want the weather parser to copy the NWS' data to. NWS Parser writes to a local file and then makes calls to that file in order to reduce the load on the NWS servers. This is set by default to /feeds/KARR.xml. B. $remotefeed - This is the XML file name of your nearest local NWS reading station. Currently, this defaults to "KARR.xml." Visit http://www.weather.gov/xml/current_obs/ to get a list of the nearest reporting stations in your area. C. $iconspath - This is the path to the locaton of the weather icons on your local server. Currently, this defaults to "/images/weather/." 4. Include Function Include the nws_weather_parser.php code in the page where you want to display your weather data. See the included sample file for how to handle the includes. Generally, the include should look like: // Include the NWS Parser function include 'nws_weather_parser.php'; Just replace 'nws_weather_parser.php' with the path to wherever the file resides on your server. For instance, the path could be '/weather/nws_weather_parser.php'. 5. Reference The Function You must actually reference the function on the page you wish to display the weather: // Call the function $xml = parseWeather($localfeed, $remotefeed); 6. Display Weather Data Display the weather data on your page. The NWS provides a PDF Product Description document that describes the XML feed and shows all the data that can be referenced. You can choose whatever pieces of data you want to display on your page. The included sample_output.php file shows you how to reference each item. All of the nodes in the XML file are stored in an array named $xml and can be easily referenced like '$xml->weather'. Product Description Document http://products.weather.gov/PDD/NWS_Current_Observations_RSS_XML.pdf
About
PHP code to read and display XML version of NWS local forecast data
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- PHP 100.0%