[weatherbug_getfullforecast]

Description

Link: [weatherbug_getfullforecast]
Author: Jason Huck
Category: Utility
Version: 8.x
License:
Posted: May. 08, 2006
Updated: Jan. 01, 0001
More by this author...
Returns a 7-day forecast for the given zip code using the WeatherBug API. The result is an array of maps containing a prediction, expected high and low temperatures, etc. for each day. Requires a valid WeatherBug API key.

Parameters

-key string, required A valid WeatherBug API key.
-zip string, required The zip code to use in the search.

Sample Usage

var('forecast') = weatherbug_getfullforecast(
	-key=$key,
	-zip=$zip
);

iterate($forecast, local('s'));
	iterate(#s->keys, local('i'));
		#i + ': ' + #s->find(#i) + '<br>\n';
	/iterate;
	
	'<br>\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.
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
define_tag(
	'getfullforecast',
	-namespace='weatherbug_',
	-required='key',
	-required='zip',
	-priority='replace',
	-description='Returns a 7-day forecast for the given zip code.'
);
	local('url' = 'http://' + #key + '.api.wxbug.net/getFullForecast.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('forecasts') = #xmldata->extract('//forecast');
	local('out' = array);
	
	local('fields') = array(
		'title',
		'short-title',
		'image',
		'description',
		'prediction',
		'high',
		'low'
	);
	
	iterate(#forecasts, local('s'));
		#s = xml('<?xml version="1.0" encoding="utf-8" ?>' + #s);
	
		local('map' = map);
		
		iterate(#fields, local('f'));
			local('v') = #s->extract('//' + #f + '/text()')->first;
			#map->insert(#f = #v);
		/iterate;
		
		#out->insert(#map);
	/iterate;
	
	return(@#out);	
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net