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) {