[backstage] Weather conditions?

2006-11-01 Thread John Wards
Right best make clear what I mean by weather conditions.

From a weather feed description for example from:
http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/4376.xml

You get:
The forecast for Hartlepool, United Kingdom on Wednesday: sunny
intervals.  Max Temp: 8°C (46°F), Min Temp: -2°C (28°F), Wind Direction:
NW, Wind Speed: 17mph, Visibility: good, Pressure: 1031mb, Humidity:
62%, UV risk: low, Pollution: N/A, Sunrise: 07:08GMT, Sunset: 16:32GMT

What I am calling a weather condition is the sunny intervals part.

Now I have used the countries opml file posted here, downloaded each
feed to find all the different conditions used and turn it into an xml
file..

What I came up with was...

conditions
condition text=sunny/
condition text=sunny intervals/
condition text=heavy showers/
condition text=light showers/
condition text=light rain/
condition text=thundery showers/
condition text=cloudy/
condition text=heavy rain/
condition text=hail showers/
condition text=light snow showers/
condition text=foggy/
condition text=light snow/
condition text=drizzle/
condition text=sleet showers/
condition text=sleet/
condition text=heavy snow showers/
condition text=heavy snow/
/conditions

The question isam I missing any? This is more a question to the
backstage team I suppose...

Oh and in the spirit of caring and sharing code below is the code that
makes the above output...its based on the countries.opml file that has
been shared out on here and used PHP5 dom and simplexml plus a simplexml
to array function I found kicking about on teh interwebs...it saves the
feeds for a while in your tmp dir...

Ta
John
---
?php

ini_set ( zlib.output_compression, 0);
ini_set ( output_handler, );
@ob_end_flush();
set_time_limit(0);
echo pre;
flush();
$xml = new DomDocument('1.0');
$xml-resolveExternals = true;
$xml-load('countries.opml');


$xmls=simplexml_import_dom($xml);

$opml=simplexml2ISOarray($xmls);

$countries = $opml[body][outline][outline];

foreach ($countries as $country){
foreach($country[outline] as $feed){
$xmlurl = $feed[@attributes][url];
$basename = basename($xmlurl);
$savefile = /tmp/.$basename;
if(file_exists($savefile)){
$maketime = filectime($savefile);
$nowtime = time();
$lesstime = $nowtime - $maketime;
}else{
$lesstime=19000;
}
if($lesstime 18000){
$xmlstr = file_get_contents($xmlurl);
$han = fopen($savefile,w);
fwrite($han,$xmlstr);
fclose($han);
}else{
$xmlstr = file_get_contents($savefile);
}
if($xmlstr){
@$xml = new DomDocument('1.0');
@$xml-resolveExternals = true;
@$xml-loadXML($xmlstr);
$array=array();

foreach($xml-getElementsBytagName('item') as $item){
$description = 
$item-getElementsByTagName('description')-item(0)-firstChild-nodeValue;
preg_match(|(The forecast for (.*), (.*) on 
.*): (.*)\. (.*)|,$description,$match);
$conditions[$match[4]] = 1;
}
echo $savefile.\n;
flush();
}
}
}
$conditions=array_keys($conditions);

//create xml doc
$doc = new DOMDocument(1.0);
$doc-formatOutput = true;
//create the weather element
$root = $doc-createElement('conditions');
$root = $doc-appendChild($root);
//create the weather_location element
if($conditions){
foreach ( $conditions as $condition )
{
//create the item element
$acondition = $doc-createElement(condition);
$acondition = $root-appendChild($acondition);
$acondition-setAttribute(text,$condition);
}
unset($conditions);
}
$han=fopen(conditions.xml,w);
fwrite($han,$doc-saveXML());
fclose($han);

function simplexml2ISOarray($xml,$attribsAsElements=0) {
if (get_class($xml) == 'SimpleXMLElement') {
$attributes = $xml-attributes();
foreach($attributes as $k=$v) {
if ($v) $a[$k] = (string) $v;
}
$x = $xml;
$xml = get_object_vars($xml);
}
if (is_array($xml)) {
if (count($xml) == 0) return (string) $x; // for CDATA
foreach($xml as $key=$value) {
$r[$key] = 
simplexml2ISOarray($value,$attribsAsElements);
if (!is_array($r[$key])) $r[$key] = 
utf8_decode($r[$key]);
}
if (isset($a)) {
if($attribsAsElements) {
 

RE: [backstage] Weather conditions?

2006-11-01 Thread Kathryn Schmitt
Hi John,

The complete list of weather conditions that appear on the BBC Weather
site is as follows:

[desc]
'clear'
'sunny'
'partly cloudy'
'sunny intervals'
'dust storm'
'misty'
'foggy'
'cloudy'
'light showers'
'drizzle'
'light rain'
'heavy showers'
'heavy rain'
'sleet showers'
'sleet'
'hail showers'
'hail'
'light snow showers'
'light snow'
'heavy snow showers'
'heavy snow'
'thundery showers'
'thunderstorm'
'tropical storm'
[/desc]

Best,
Kass

Kathryn Schmitt
Senior Developer
BBC Weather Centre
2026 Television Centre
T: 020 82259448
M: 0771 7582482

www.bbc.co.uk/weather
www.bbc.co.uk/climate

 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of John Wards
 Sent: 01 November 2006 16:27
 To: backstage@lists.bbc.co.uk
 Subject: [backstage] Weather conditions?

 The question isam I missing any? This is more a question 
 to the backstage team I suppose...

-
Sent via the backstage.bbc.co.uk discussion group.  To unsubscribe, please 
visit http://backstage.bbc.co.uk/archives/2005/01/mailing_list.html.  
Unofficial list archive: http://www.mail-archive.com/backstage@lists.bbc.co.uk/