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
|
define_tag(
'getlivecompactweather',
-namespace='weatherbug_',
-required='key',
-required='zip',
-required='station',
-priority='replace',
-description='Returns compact live weather conditions for the given WeatherBug station.'
);
local('url' = 'http://' + #key + '.api.wxbug.net/getLiveCompactWeather.aspx');
local('getparams') = array(
'acode' = #key,
'zipcode' = #zip,
'StationID' = #station
);
local('response') = include_url(
#url,
-getparams=#getparams
);
#response->replace(' xmlns:aws="http://www.aws.com/aws"','')&replace('aws:','');
local('xmldata') = xml(#response);
local('out' = map);
local('fields') = array(
'temp',
'rain-today',
'wind-speed',
'wind-direction',
'gust-speed',
'gust-direction'
);
iterate(#fields, local('f'));
local('map' = map);
if((: 'wind-direction', 'gust-direction') !>> #f);
local('u') = string(#xmldata->extract('//' + #f + '/@units')->first)->split('="')->second;
#u->removetrailing('"');
#u = decode_xml(#u);
else;
local('u') = null;
/if;
local('v') = #xmldata->extract('//' + #f + '/text()')->first;
#map->insert('value' = #v);
#map->insert('units' = #u);
#out->insert(#f = #map);
/iterate;
return(@#out);
/define_tag;
|