Lasso Soft Inc. > Home

[weatherbug_getstations]

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

Description

Returns a list of WeatherBug stations in a zip code. Requires a valid WeatherBug API Key.

Sample Usage

var('stations') = weatherbug_getstations(
	-key=$key,
	-zip=$zip
);

iterate($stations, local('s'));
	iterate(#s->keys, local('i'));
		#i + ': ' + #s->find(#i) + '
\n'; /iterate; '
\n' * 2; /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(
	'getstations',
	-namespace='weatherbug_',
	-required='key',
	-required='zip',
	-priority='replace',
	-description='Returns a list of WeatherBug stations in a zip code.'
);
	local('url' = 'http://' + #key + '.api.wxbug.net/getStations.aspx');
	local('getparams') = array(
		'acode' = #key,
		'zipcode' = #zip
	);
	
	local('response') = include_url(
		#url,
		-getparams=#getparams
	);
	
	#response->replace(' xmlns:aws="http://www.aws.com/aws"','')&replace('aws:','');
	
	local('xmldata') = xml(#response);
	local('stations') = #xmldata->extract('//station');
	local('out' = array);
	
	local('fields') = array(
		'id',
		'name',
		'city',
		'state',
		'zipcode',
		'distance',
		'station-type'
	);
	
	iterate(#stations, local('s'));
		#s = xml('' + #s);
	
		local('map' = map);
		
		iterate(#fields, local('f'));
			local('v') = string(#s->extract('//@' + #f)->first)->split('="')->second;
			#v->removetrailing('"');
			#map->insert(#f = #v);
		/iterate;
		
		#out->insert(#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