jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_external.php] - Diff between revs 1 and 85

Show entire file Ignore whitespace

Rev 1 Rev 85
Line 32... Line 32...
} }
} }
   
function ReadData($targetstring, &$map, &$item) function ReadData($targetstring, &$map, &$item)
{ {
$inbw=-1; $data[IN] = NULL;
$outbw=-1; $data[OUT] = NULL;
$data_time = 0; $data_time = 0;
   
if(preg_match("/^!(.*)$/",$targetstring,$matches)) if(preg_match("/^!(.*)$/",$targetstring,$matches))
{ {
$command = $matches[1]; $command = $matches[1];
   
debug("ExternalScript ReadData: Running $command\n"); debug("ExternalScript ReadData: Running $command\n");
// run the command here // run the command here
if( ($pipe = popen($command,"r")) === false) if( ($pipe = popen($command,"r")) === false)
{ {
warn("ExternalScript ReadData: Failed to run external script.\n"); warn("ExternalScript ReadData: Failed to run external script. [WMEXT01]\n");
} }
else else
{ {
$i=0; $i=0;
while( ($i <5) && ! feof($pipe) ) while( ($i <5) && ! feof($pipe) )
Line 57... Line 57...
} }
pclose($pipe); pclose($pipe);
   
if($i==5) if($i==5)
{ {
$inbw = floatval($lines[0]); $data[IN] = floatval($lines[0]);
$outbw = floatval($lines[1]); $data[OUT] = floatval($lines[1]);
   
  $item->add_hint("external_line1",$lines[0]);
  $item->add_hint("external_line2",$lines[1]);
  $item->add_hint("external_line3",$lines[2]);
  $item->add_hint("external_line4",$lines[3]);
$data_time = time(); $data_time = time();
} }
else else
{ {
warn("ExternalScript ReadData: Not enough lines read from external script ($i read, 4 expected)\n"); warn("ExternalScript ReadData: Not enough lines read from external script ($i read, 4 expected) [WMEXT02]\n");
} }
} }
} }
   
debug ("ExternalScript ReadData: Returning ($inbw,$outbw,$data_time)\n"); debug ("ExternalScript ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[OUT]).",$data_time)\n");
   
return( array($inbw, $outbw, $data_time) ); return( array($data[IN], $data[OUT], $data_time) );
} }
} }
   
// vim:ts=4:sw=4: // vim:ts=4:sw=4:
   

Powered by WebSVN 2.2.1