1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
define_tag(
'getliveweather',
-namespace='weatherbug_',
-required='key',
-required='zip',
-required='station',
-priority='replace',
-description='Returns live weather conditions for the given WeatherBug station.'
);
local('url' = 'http://' + #key + '.api.wxbug.net/getLiveWeather.aspx');
local('getparams') = array(
'acode' = #key,
'zipcode' = #zip,
'StationID' = #station
);
local('response') = include_url(
#url,
-getparams=#getparams
);
local('xmldata') = xml_tree(#response);
local('times') = array(
'ob-date',
'gust-time',
'sunrise',
'sunset'
);
local('out' = map);
iterate(#xmldata->ob->children, local('i'));
if(#i->name && #i->name != 'text');
if(#times !>> #i->name);
local('map' = map);
#map->insert('value' = #i->contents);
#i->attributes->size ? #map->insert(#i->attributes->first->first = decode_xml(#i->attributes->first->second));
#out->insert(#i->name = #map);
else;
local(
'yr' = #i->year->attribute('number'),
'mo' = #i->month->attribute('number'),
'dy' = #i->day->attribute('number'),
'H' = #i->hour->attribute('hour-24'),
'M' = #i->minute->attribute('number'),
'S' = #i->second->attribute('number'),
);
local('datestring') = #yr + '-' + #mo + '-' + #dy + ' ' + #H + ':' + #M + ':' + #S;
local('date') = date(#datestring, -format='%Y-%m-%d %H:%M:%S');
#out->insert(#i->name = #date);
/if;
/if;
/iterate;
return(@#out);
/define_tag;
|