1

I want to develop a weather web service and I just want to get the information of weather forecasts.

Than I create my own interface. But I can't find how I access these datas.

How can I access weather datas? Thank you.

e.ozmen
  • 269
  • 2
  • 17

3 Answers3

3

I made a Weather API available on mashape, and they have a ready to use simple PHP SDK. This api is really simple to use because we use the cool standards that are available nowadays, like JSON and REST.

If you like it please give it a try on mashape

iwasrobbed
  • 45,197
  • 20
  • 140
  • 190
Howdy Clowdy
  • 121
  • 4
2

What you're probably looking for is data straight from the source. I provided a pretty thorough overview on this other stackoverflow question, but below is are the basics:

Data sources

The best place to get the data is from the National Weather Service and it's affiliates. They have forecasts not only for the US, but the entire world. To get the quantity of data you're looking for, you'll want to access it pragmatically... these are probably your best bets:

http://nomads.ncdc.noaa.gov/dods/ <- good for historical data
http://nomads.ncep.noaa.gov/dods/ <- good for recent data

Logging the data to a database

With the amount of data you'll need, you'll probably want to store everything in a database... this way it can be quickly accessed and served. A good option would using either MySQL or PostGRES along with PyDAP or NetCDF. An option for you may be this python forecasting module, which combines PyDAP with PostGRES:

http://getforecasting.com

An example from the homepage of the downloading an entire forecast for a one day period:

from forecasting import Model

rap = Model('rap')
rap.connect(database='weather', user='chef')
fields = ['tmp2m']
rap.transfer(fields)

Using the data

With the data now in a database, it's as easy as querying for anything you need. For example, getting the latest forecast from the Rapid Refresh model:

select
ST_X(geom),
ST_Y(geom),
value
from data
inner join gridpoints gp on data.gridid = gp.gridpointid
inner join forecasts fcst on data.forecastid = fcst.forecastid
inner join fields fld on fcst.fieldid = fld.fieldid
inner join models m on fld.modelid = m.modelid
where 
m.name = 'rap'
and fld.name = 'tmp2m'
and fcst.datatime = (select max(datatime) from forecasts where forecasts.fieldid = fld.fieldid)
and fcst.datatimeforecast = (select min(datatimeforecast) from forecasts where forecasts.datatime = fcst.datatime)
order by gp.ord;
Community
  • 1
  • 1
sAlexander
  • 651
  • 2
  • 8
  • 7
1

You can use yahoo API . Following is example (in PHP):

    if(isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])){
        $zipcode = $_POST['zipcode'];
    }else{
        $zipcode = '50644';
    }
    $result = file_get_contents('http://weather.yahooapis.com/forecastrss?p=' . $zipcode . '&u=f');
    $xml = simplexml_load_string($result);

    //echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8');

    $xml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
    $location = $xml->channel->xpath('yweather:location');

    if(!empty($location)){
        foreach($xml->channel->item as $item){
            $current = $item->xpath('yweather:condition');
            $forecast = $item->xpath('yweather:forecast');
            $current = $current[0];
            $output = <<<END
                <h1 style="margin-bottom: 0">Weather for {$location[0]['city']}, {$location[0]['region']}</h1>
                <small>{$current['date']}</small>
                <h2>Current Conditions</h2>
                <p>
                <span style="font-size:72px; font-weight:bold;">{$current['temp']}&deg;F</span>
                <br/>
                <img src="http://l.yimg.com/a/i/us/we/52/{$current['code']}.gif" style="vertical-align: middle;"/>&nbsp;
                {$current['text']}
                </p>
                <h2>Forecast</h2>
                {$forecast[0]['day']} - {$forecast[0]['text']}. High: {$forecast[0]['high']} Low: {$forecast[0]['low']}
                <br/>
                {$forecast[1]['day']} - {$forecast[1]['text']}. High: {$forecast[1]['high']} Low: {$forecast[1]['low']}
                </p>
    END;
        }
    }else{
        $output = '<h1>No results found, please try a different zip code.</h1>';
    }
    ?>
    <html>
    <head>
    <title>Weather</title>
    <style>
    body {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
    }
    label {
        font-weight: bold;
    }
    </style>
    </head>
    <body>
    <form method="POST" action="">
    <label>Zip Code:</label> <input type="text" name="zipcode" size="8" value="" /><br /><input type="submit" name="submit" value="Lookup Weather" />
    </form>
    <hr />
    <?php echo $output; ?>
Kamesh Jungi
  • 5,684
  • 5
  • 35
  • 48