James Linden

~# data ninja / linux guru / web dev geek / robotics nerd / idea machine / N6NRD

Datasets / Weather Reporting Station List Importer

Reporting Station List Importer

Overview

Weather.gov Reporting Station List Importer is a script to parse the XML file provided by weather.gov and insert the records into a MySQL database.

Dataset Source

URL: http://www.weather.gov/xml/current_obs/index.xml

Updates: infrequently

Environment

  • GNU/Linux
  • PHP 5.3 +
  • MySQL 5.x

Notes

  • This script is designed to run on the command line.

Howto

Create the database (insert your database name):

CREATE DATABASE IF NOT EXISTS database_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;

Create the table:

CREATE TABLE IF NOT EXISTS t_station (
c_id SERIAL PRIMARY KEY,
c_code VARCHAR(8) DEFAULT NULL,
c_state VARCHAR(2) DEFAULT NULL,
c_name VARCHAR(64) DEFAULT NULL,
c_lat DEC(7,4) SIGNED DEFAULT NULL,
c_lng DEC(7,4) SIGNED DEFAULT NULL,
c_uxml VARCHAR(128) DEFAULT NULL,
c_urss VARCHAR(128) DEFAULT NULL,
c_uhtml VARCHAR(128) DEFAULT NULL
) ENGINE=MyISAM;

Download weather.gov-stationlist-import.php and edit it, setting your database configuration:

$CFG['db']['host'] = 'localhost';
$CFG['db']['port'] = 3306;
$CFG['db']['user'] = null;
$CFG['db']['pass'] = null;
$CFG['db']['name'] = null;

Run the script -- it should only require a few seconds.

License

This project is BSD (2 clause) licensed.

photo of James Linden
Founder / Head Geek
Digital Dock, LLC
aka kodekrash & N6NRD
Alexandria, LA USA

What I Do

Linux administration & virtualization
Data mining, storage & analysis
Web development

What I've Done

Rescued a skunk
Built Prime GNU/Linux
Contributed to Spidering Hacks