jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_tabfile.php] - Blame information for rev 71

 

Line No. Rev Author Line
11simandl<?php
2// Sample Pluggable datasource for PHP Weathermap 0.9
3// - read a pair of values from a database, and return it
4 
5// TARGET dbplug:databasename:username:pass:hostkey
6 
7class WeatherMapDataSource_tabfile extends WeatherMapDataSource {
8 
9 function Recognise($targetstring)
10 {
11 if(preg_match("/\.(tsv|txt)$/",$targetstring,$matches))
12 {
13 return TRUE;
14 }
15 else
16 {
17 return FALSE;
18 }
19 }
20 
21 // function ReadData($targetstring, $configline, $itemtype, $itemname, $map)
22 function ReadData($targetstring, &$map, &$item)
23 {
24 $inbw=-1;
25 $outbw=-1;
26 $data_time=0;
27 $itemname = $item->name;
28 
29 $matches=0;
30 
31 $fd=fopen($targetstring, "r");
32 
33 if ($fd)
34 {
35 while (!feof($fd))
36 {
37 $buffer=fgets($fd, 4096);
38 # strip out any Windows line-endings that have gotten in here
39 $buffer=str_replace("\r", "", $buffer);
40 
41 if (preg_match("/^$itemname\t(\d+\.?\d*[KMGT]*)\t(\d+\.?\d*[KMGT]*)/", $buffer, $matches))
42 {
43 $inbw=unformat_number($matches[1]);
44 $outbw=unformat_number($matches[2]);
45 }
46 }
47 $stats = stat($targetstring);
48 $data_time = $stats['mtime'];
49 }
50 else {
51 // some error code to go in here
52 debug ("TabText ReadData: Couldn't open ($targetstring). \n"); }
53 
54 debug ("TabText ReadData: Returning ($inbw,$outbw,$data_time)\n");
55 
56 return ( array($inbw,$outbw,$data_time) );
57 }
58}
59 
60// vim:ts=4:sw=4:
61?>

Powered by WebSVN 2.2.1