Lasso Soft Inc. > Home

[weatherbug_getlivecompactweather]

Linkweatherbug_getlivecompactweather
AuthorJason Huck
CategoryUtility
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted08 May 2006
Updated08 May 2006
More by this author...

Description

Returns compact live weather conditions (temperature, rain, wind, and gusting) for the given WeatherBug station. Requires a valid WeatherBug API key.

Sample Usage

var('compact') = weatherbug_getlivecompactweather(
	-key=$key,
	-zip=$zip,
	-station='XXXXX'
);

iterate($compact->keys, local('i'));
	#i + ': ' + $compact->find(#i)->find('value') + ' ' + $compact->find(#i)->find('units') + '
\n'; /iterate;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

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;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft