Re: [backstage] Newcastle labs

2006-11-13 Thread John Wards
Yip I'm going...getting let out of the office for the day!

John

On Mon, 2006-11-13 at 13:35 +, gareth rushgrove wrote:
 Hi All
 
 Just wondering if anyone else is going to be along to the BBC
 Innovation Labs tomorrow in Newcastle
 (http://open.bbc.co.uk/labs/2007/n-england/)? or if anyone has been to
 previous events and has anything to say about them?
 
 Just got confirmation that I can go along, hence the last minute email.
 
 Thanks
 
 Gareth
 

-
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/


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

[backstage] PHP Code for weather conditions

2006-11-01 Thread John Wards
Right heres a little snippet of code to play with the description from
the weather feeds.

$description = 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;
preg_match(|(The forecast for (.*), (.*) on .*): (.*)\. 
(.*)|,$description,$match);
preg_match_all(| (.*): (.*),|U,$match[5].,,$matches,PREG_SET_ORDER);
-
If you print_r out $match and $matches you should see how useful this would be.

It works with the current format of the description the Beeb uses.

Cheers
John

-
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/


Re: [backstage] PHP Code for weather conditions

2006-11-01 Thread John Wards
Quoting Matthew Somerville [EMAIL PROTECTED]:
  preg_match_all(| (.*): (.*),|U,$match[5].,,$matches,PREG_SET_ORDER);

 This doesn't catch Sunset, due to you forcing that comma. Try:
  '| (.*): (.*)(,|\.|$)|U'
 (I can't remember if I put the full stop in there just in case, or if I had
 an actual example using it, sorry.)

Ah it does though as I add a , to the end of the subject which catches the
sunset.

Cheers
John
-
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/