[weatherbug_getliveweather]

Description

Link: [weatherbug_getliveweather]
Author: Jason Huck
Category: Utility
Version: 8.x
License:
Posted: May. 08, 2006
Updated: Jan. 01, 0001
More by this author...
Returns detailed, live current weather conditions via the WeatherBug API. Requires a valid WeatherBug API key. This tag also requires the [xml_tree] type.

Parameters

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

Sample Usage

var('full') = weatherbug_getliveweather(
	-key=$key,
	-zip=$zip,
	-station='XXXXX'
);

iterate($full->keys, local('i'));
	#i + ': ';
	
	protect;
		local('x') = @$full->find(#i);
		
		if(#x->isa('map'));
			#x->find('value') + ' ';
			#i == 'moon-phase' ? #x->find('moon-phase-img') | #x->find('units');
		else;
			#x;
		/if;
	/protect;
	
	'<br>\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.
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;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net