Lasso Soft Inc. > Home

[weatherbug]

Linkweatherbug
AuthorJason Huck
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted24 May 2007
Updated24 May 2007
More by this author...

Description

This custom type provides a complete interface to the WeatherBug pipe-delimited API. This version of the API is only available for US data. Requires a valid API key. For more information and to see a complete list of return values for each method, consult the documentation.

Instance Variables:

->key: Your WeatherBug API key.
->ZipCode: A US postal code.
->StationID: A valid WeatherBug station ID.
->Units: Use 0 for English, 1 for Metric.

Member Tags:

->getliveweather: Returns a map of current weather conditions for the given zip code or WeatherBug station, including the temperature, humidity, barometric pressure, wind speed, wind direction, etc.

->gettwodayforecast: Returns a map of forecast data for today and tomorrow, including highs and lows.

->getthreedayforecast: Same as ->gettwodayforecast plus one more day.

->getstations: Returns a list of all the WeatherBug stations near the given zip code, including the station name, ID, and distance from the zip code's center.

->getalerts: Returns a list of all current weather alerts for the given zip code or station ID.

->getcondition: Returns information about the given WeatherBug condition code as an array containing two elements: the time of day and the current conditions.

->getalert: Returns a description of the given WeatherBug alert code.

Sample Usage

[//lasso
	var('wb') = weatherbug(
		-key='xxxxxxx',
		-zipcode=90210,
		-units=0
	);
	
	var('data') = $wb->getthreedayforecast;
	
	iterate($data, local('i'));
		#i->first + ': ' + #i->second + '
\n'; /iterate; ] Returns: Tomorrow High: 65° Today Title: Tonight Third day Condition Text 1: Sunny after morning low Third day Condition Text 2: clouds and fog... Today High: -- Third day Condition #: 3 Today Condition #: 2 Today Low: 58° SunSet: 1180050840 Tomorrow Title: Friday UpdateTime: 02:11 PM PDT May 24, 2007 Tomorrow Condition #: 3 Magic Number: 31 Third day Title: Saturday Tomorrow Low: 58° Today Condition Text 1: Clear early then low Today Condition Text 2: clouds and fog... SunRise: 1179999960 Third day Low: 58° Tomorrow Condition Text 1: Sunny after morning low Tomorrow Condition Text 2: clouds and fog... Frequency: 3600 Third day High: 65°

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_type(
		'weatherbug',
		-prototype,
		-description='Interfaces with the WeatherBug Pipe Delimited API.'
	);
		local(
			'key' = string,
			'ZipCode' = integer,
			'StationID' = string,
			'Units' = 0,
			't' = integer,
			'required' = (: 'key', 'ZipCode', 'StationID', 'Units', 't'),
			'baseurl' = '.isapi.wxbug.net/',
			'methods' = map(
				'getliveweather' = map(
					'methodexe' = 'WxDataISAPI/WxDataISAPI.dll',
					'getparams' = array(
						'Magic' = 10991,
						'RegNum' = 0,
						'ZipCode' = null, 	// ZIP
						'StationID' = null,	// StationID
						'Units' = integer,	// 0 or 1
						'Version' = 7,
						'Fore' = 0,
						't' = null			// UID
					),
					'returnvalues' = array(
						'Magic Number',
						'Time',
						'Date',
						'Temperature',
						'Wind direction',
						'Wind Speed',
						'Gust Wind Direction',
						'Gust Wind Speed',
						'Today Rainfall',
						'Rainfall Rate',
						'Barometer',
						'Humidity',
						'High Temp',
						'Low Temp',
						'Dew Point',
						'Wind Chill',
						'Monthly Rain',
						'Temperature Rate',
						'Humidity Rate',
						'Barometer Rate',
						'High Humidity',
						'Low Humidity',
						'High Barometer',
						'Low Barometer',
						'Max Rain Rate',
						'Gust Time',
						'Average Wind Direction',
						'Average Wind Speed',
						'Indoor Temp',
						'Auxiliary Temp',
						'Light',
						'Yearly Rainfall',
						'Indoor Temp Rate',
						'Aux Temp Rate',
						'Light Rate',
						'Station Name',
						'City and State Name',
						'Active Query Frequency',
						'Inactive/Background Query Frequency'
					)
				),
				'gettwodayforecast' = map(
					'methodexe' = 'forecastISAPI/ForecastISAPI.dll',
					'getparams' = array(
						'Magic' = 10992,
						'RegNum' = 0,
						'ZipCode' = null,	// ZIP
						'StationID' = null,	// StationID
						'Version' = 7,
						'Units' = integer,	// 0 or 1
						't' = null			// UID
					),
					'returnvalues' = array(
						'Magic Number',
						'ForeCastTitle1',
						'High1',
						'Low1',
						'Condition1',
						'ForeCastTitle2',
						'High2',
						'Low2',
						'Condition2',
						'Sunrise',
						'Sunset',
						'Query Frequency'
					)
				),	
				'getthreedayforecast' = map(
					'methodexe' = 'forecastISAPI/ForecastISAPI.cgi',
					'getparams' = array(
						'GetForecast60',
						'Magic' = 10992,
						'RegNum' = 0,
						'ZipCode' = null,	// ZIP
						'StationID' = null,	// StationID
						'Version' = 7,
						'Units' = integer,	// 0 or 1
						't' = null,			// UID
						'lv' = 0
					),
					'returnvalues' = array(
						'Magic Number',
						'UpdateTime',		// unix timestamp
						'Today Title',
						'Today High',
						'Today Low',
						'Today Condition #',
						'Today Condition Text 1',
						'Today Condition Text 2',
						'Tomorrow Title',
						'Tomorrow High',
						'Tomorrow Low',
						'Tomorrow Condition #',
						'Tomorrow Condition Text 1',
						'Tomorrow Condition Text 2',
						'Third day Title',
						'Third day High',
						'Third day Low',
						'Third day Condition #',
						'Third day Condition Text 1',
						'Third day Condition Text 2',
						'SunRise',			// unix timestamp
						'SunSet',			// unix timestamp
						'Frequency'
					)
				),
				'getstations' = map(
					'methodexe' = 'wxdataisapi/wxdataisapi.dll',
					'getparams' = array(
						'getstations',
						'ZipCode' = null,	// ZIP
						'magic' = 21771
					),
					'returnvalues' = array(
						'Magic Number',
						'NoofStations',
						'ZipCode',
						'StationID',		// items from here down repeat for each station found
						'Station Name',
						'City, State',
						'Distance from Zip Code center',
						'Station_Type',		// 0:Internet 1:Modem 
						'City, State of Given ZipCode'
					)
				),
				'getalerts' = map(
					'methodexe' = 'WxAlertISAPI/WxAlertIsapi.cgi',
					'getparams' = array(
						'GetAlert60',
						'Magic' = 160,
						'ZipCode' = null,	// ZIP
						'StationID' = null,	// StationID
						'Units' = integer,	// 0 or 1
						'RegNum' = 0,
						'Version' = 7,
						't' = null,			// UID
						'lv' = 0
					),
					'returnvalues' = array(
						'Magic Number',
						'Interval',			// seconds
						'Number of Alerts',	// up to 10
						'Alert ID',			// items from here down repeat for each alert found
						'Alert Type',
						'Alert Expires'		// unix timestamp (UTC)
					)
				)
			),			
			'alerts' = map(
				2 = 'Coastal Flood Warning',
				3 = 'Flash Flood Warning',
				21 = 'Flood Warning',
				22 = 'Lakeshore Warning Statement',
				23 = 'Marine Advisory / Warning',
				24 = 'Special Marine Warning',
				25 = 'Severe Thunderstorm Warning',
				26 = 'Tornado Warning',
				27 = 'Tsunami Watch / Warning',
				28 = 'Coastal Flood Watch',
				29 = 'Coastal Flood Statement',
				30 = 'Flash Flood Watch',
				31 = 'Flash Flood Statement',
				32 = 'Flood Statement',
				33 = 'Hurricane Local Statement',
				34 = 'Marine Weather Statement',
				35 = 'Severe Local Storm Watch',
				36 = 'Severe Local Storm Watch Area Outline',
				37 = 'Severe Weather Statement',
				38 = 'Severe Local Storm Watch',
				39 = 'Watch by  County Outline',
				40 = 'Severe Local Storm Watch',
				81 = 'Winter Storm Warning',
				101 = 'Non Precipitation Advisory',
				102 = 'Storm Warning Outline',
				103 = 'Dust Storm Warning',
				121 = 'Earthquake Summary',
				122 = 'Winter Storm Watch',
				161 = 'High Surf Warning',
				180 = 'Civil Emergency Message',
				181 = 'Tornado Watch',
				182 = 'Severe Thunderstorm Watch',
				183 = 'Winter Weather Advisory',
				201 = 'NBC StormCenter Update',
				202 = 'NOW Forecast',
				221 = 'Local Forecast',
				241 = 'Fire Weather Message',
				261 = 'Storm Information',
				262 = 'Local Storm Report',
				282 = 'Hurricane Forecast Advisory',
				283 = 'Hurricane Public Advisory',
				284 = 'Hurricane Discussion',
				285 = 'Hurrican Probabilities',
				286 = 'Tropical Storm Warning',
				287 = 'Tropical Storm Watch',
				300 = 'Administrative Message',
				301 = 'Avalanche Watch',
				302 = 'Avalanche Warning',
				303 = 'Child Abduction Emergency',
				304 = 'Civil Danger Warning',
				305 = 'Earthquake Warning',
				306 = 'Evacuation Immediate',
				307 = 'Fire Warning',
				308 = 'Hazardous Materials Warning',
				309 = 'Law Enforcement Warning',
				310 = 'Local Area Emergency',
				311 = '911 Telephone Outage Emergency',
				312 = 'Nuclear Power Plant Warning',
				313 = 'Radiological Hazard Warning',
				314 = 'Shelter In Place Warning',
				315 = 'Volcano Warning',
				400 = 'Tropical Rainfall Estimate',
				401 = 'Tropical Position Estimate',
				402 = 'Tropical Cyclone Update',
				403 = 'Tropical Disturbance Statement',
				404 = 'Tropical Weather Outlook',
				405 = 'Monthly Tropical Weather Summary',
				406 = 'Tropical Weather Discussion',
				407 = 'Wind Speed Probabilities'
			),
			'conditions' = map(
				0 = (: 'Day', 'Clear'),
				1 = (: 'Day', 'Cloudy'),
				2 = (: 'Night', 'Partly Cloudy'),
				3 = (: 'Day', 'Partly Cloudy'),
				4 = (: 'Day', 'Partly Sunny'),
				5 = (: 'Day', 'Rain'),
				6 = (: 'Day', 'Thunderstorms'),
				7 = (: 'Day', 'Sunny'),
				8 = (: 'Day', 'Snow'),
				9 = (: 'Day', 'Flurries'),
				10 = (: 'Either', 'Unknown'),
				11 = (: 'Day', 'Chance of Snow'),
				12 = (: 'Night', 'Snow'),
				13 = (: 'Night', 'Cloudy'),
				14 = (: 'Night', 'Rain'),
				15 = (: 'Night', 'Chance of Rain'),
				16 = (: 'Night', 'Partly Sunny'),
				17 = (: 'Night', 'Sunny'),
				18 = (: 'Night', 'Thunderstorms'),
				19 = (: 'Day', 'Chance of Flurry'),
				20 = (: 'Day', 'Chance of Rain'),
				21 = (: 'Day', 'Chance of Sleet'),
				22 = (: 'Day', 'Chance of Storms'),
				23 = (: 'Day', 'Hazy'),
				24 = (: 'Day', 'Mostly Cloudy'),
				25 = (: 'Day', 'Sleet'),
				26 = (: 'Day', 'Mostly Sunny'),
				27 = (: 'Night', 'Chance of Flurry'),
				28 = (: 'Night', 'Chance of Sleet'),
				29 = (: 'Night', 'Chance of Snow'),
				30 = (: 'Night', 'Chance of Storms'),
				31 = (: 'Night', 'Clear'),
				32 = (: 'Night', 'Flurries'),
				33 = (: 'Night', 'Hazy'),
				34 = (: 'Night', 'Mostly Cloudy'),
				35 = (: 'Night', 'Mostly Sunny'),
				36 = (: 'Night', 'Sleet'),
				37 = (: 'Either', 'Unknown'),
				38 = (: 'Day', 'Chance of Rain Showers'),
				39 = (: 'Day', 'Chance of Snow Showers'),
				40 = (: 'Day', 'Snow Showers'),
				41 = (: 'Day', 'Rain Showers'),
				42 = (: 'Night', 'Chance of Rain Showers'),
				43 = (: 'Night', 'Chance of Snow Showers'),
				44 = (: 'Night', 'Snow Showers'),
				45 = (: 'Night', 'Rain Showers'),
				46 = (: 'Day', 'Freezing Rain'),
				47 = (: 'Night', 'Freezing Rain'),
				48 = (: 'Day', 'Chance Freezing Rain'),
				49 = (: 'Night', 'Chance Freezing Rain'),
				50 = (: 'Day', 'Windy'),
				51 = (: 'Day', 'Fog'),
				52 = (: 'Day', 'Scattered Showers'),
				53 = (: 'Day', 'Scattered Thunderstorms'),
				54 = (: 'Day', 'Light Snow'),
				55 = (: 'Day', 'Chance of Light Snow'),
				56 = (: 'Day', 'Frozen Mix'),
				57 = (: 'Day', 'Chance of Frozen Mix'),
				58 = (: 'Day', 'Drizzle'),
				59 = (: 'Day', 'Chance of Drizzle'),
				60 = (: 'Day', 'Freezing Drizzle'),
				61 = (: 'Day', 'Chance of Freezing Drizzle'),
				62 = (: 'Day', 'Heavy Snow'),
				63 = (: 'Day', 'Heavy Rain'),
				64 = (: 'Day', 'Hot and Humid'),
				65 = (: 'Day', 'Very Hot'),
				66 = (: 'Day', 'Increasing Clouds'),
				67 = (: 'Day', 'Clearing'),
				68 = (: 'Day', 'Mostly Cloudy'),
				69 = (: 'Day', 'Very Cold'),
				70 = (: 'Night', 'Mostly Clear'),
				71 = (: 'Night', 'Increasing Clouds'),
				72 = (: 'Night', 'Clearing'),
				73 = (: 'Night', 'Mostly Cloudy'),
				74 = (: 'Night', 'Very Cold'),
				75 = (: 'Night', 'Warm and Humid'),
				76 = (: 'Either', 'now'),
				77 = (: 'Either', 'exclamation'),
				78 = (: 'Day', '30% Chance of Snow'),
				79 = (: 'Day', '40% Chance of Snow'),
				80 = (: 'Day', '50% Chance of Snow'),
				81 = (: 'Day', '30% Chance of Rain'),
				82 = (: 'Day', '40% Chance of Rain'),
				83 = (: 'Day', '50% Chance of Rain'),
				84 = (: 'Day', '30% Chance of Flurry'),
				85 = (: 'Day', '40% Chance of Flurry'),
				86 = (: 'Day', '50% Chance of Flurry'),
				87 = (: 'Day', '30% Chance of Rain'),
				88 = (: 'Day', '40% Chance of Rain'),
				89 = (: 'Day', '50% Chance of Rain'),
				90 = (: 'Day', '30% Chance of Sleet'),
				91 = (: 'Day', '40% Chance of Sleet'),
				92 = (: 'Day', '50% Chance of Sleet'),
				93 = (: 'Day', '30% Chance of Storms'),
				94 = (: 'Day', '40% Chance of Storms'),
				95 = (: 'Day', '50% Chance of Storms'),
				96 = (: 'Day', '30% Chance of Flurry'),
				97 = (: 'Day', '40% Chance of Flurry'),
				98 = (: 'Day', '50% Chance of Flurry'),
				99 = (: 'Day', '30% Chance of Sleet'),
				100 = (: 'Day', '40% Chance of Sleet'),
				101 = (: 'Day', '50% Chance of Sleet'),
				102 = (: 'Night', '30% Chance of Snow'),
				103 = (: 'Night', '40% Chance of Snow'),
				104 = (: 'Night', '50% Chance of Snow'),
				105 = (: 'Night', '30% Chance of Storms'),
				106 = (: 'Night', '40% Chance of Storms'),
				107 = (: 'Night', '50% Chance of Storms'),
				108 = (: 'Night', '30% Chance Rain Shower'),
				109 = (: 'Night', '40% Chance Rain Shower'),
				110 = (: 'Night', '50% Chance Rain Shower'),
				111 = (: 'Night', '30% Chance Snow Shower'),
				112 = (: 'Night', '40% Chance Snow Shower'),
				113 = (: 'Night', '50% Chance Snow Shower'),
				114 = (: 'Night', '30% Chance Rain Shower'),
				115 = (: 'Night', '40% Chance Rain Shower'),
				116 = (: 'Night', '50% Chance Rain Shower'),
				117 = (: 'Night', '30% Chance Snow Shower'),
				118 = (: 'Night', '40% Chance Snow Shower'),
				119 = (: 'Night', '50% Chance Snow Shower'),
				120 = (: 'Day', '30% Chance Freezing Rain'),
				121 = (: 'Day', '40% Chance Freezing Rain'),
				122 = (: 'Day', '50% Chance Freezing Rain'),
				123 = (: 'Day', '30% Chance Freezing Rain'),
				124 = (: 'Day', '40% Chance Freezing Rain'),
				125 = (: 'Day', '50% Chance Freezing Rain'),
				126 = (: 'Day', '30% Chance of Light Snow'),
				127 = (: 'Day', '40% Chance of Light Snow'),
				128 = (: 'Day', '50% Chance of Light Snow'),
				129 = (: 'Day', '30% Chance of Frozen Mix'),
				130 = (: 'Day', '40% Chance of Frozen Mix'),
				131 = (: 'Day', '50% Chance of Frozen Mix'),
				132 = (: 'Day', '30% Chance of Drizzle'),
				133 = (: 'Day', '40% Chance of Drizzle'),
				134 = (: 'Day', '50% Chance of Drizzle'),
				135 = (: 'Day', '30% Chance Freezing Drizzle'),
				136 = (: 'Day', '40% Chance Freezing Drizzle'),
				137 = (: 'Day', '50% Chance Freezing Drizzle'),
				138 = (: 'Day', 'Chance of Snow'),
				139 = (: 'Night', 'Chance of Rain'),
				140 = (: 'Day', 'Chance of Flurry'),
				141 = (: 'Day', 'Chance of Rain'),
				142 = (: 'Day', 'Chance of Sleet'),
				143 = (: 'Day', 'Chance of Storms'),
				144 = (: 'Night', 'Chance of Flurry'),
				145 = (: 'Night', 'Chance of Sleet'),
				146 = (: 'Night', 'Chance of Snow'),
				147 = (: 'Night', 'Chance of Storms'),
				148 = (: 'Day', 'Chance Rain Shower'),
				149 = (: 'Day', 'Chance Snow Shower'),
				150 = (: 'Night', 'Chance Rain Shower'),
				151 = (: 'Night', 'Chance Snow Shower'),
				152 = (: 'Day', 'Chance Freezing Rain'),
				153 = (: 'Night', 'Chance Freezing Rain'),
				154 = (: 'Day', 'Chance of Light Snow'),
				155 = (: 'Day', 'Chance of Frozen Mix'),
				156 = (: 'Day', 'Chance of Drizzle'),
				157 = (: 'Day', 'Chance Freezing Drizzle')
			)			
		);
		
		define_tag('oncreate');
			self->setparams(params);
		/define_tag;
		
		define_tag('setparams', -req='params', -copy);
			self->t = lasso_uniqueid;		
			iterate(self->required, local('i'));
				#params >> ('-' + #i) ? self->#i = #params->find('-' + #i)->first->second;
			/iterate;
		/define_tag;

		define_tag('checkparams');
			return(boolean(self->key && (self->ZipCode || self->stationID)));
		/define_tag;
		
		define_tag('getcondition', -req='num');
			local('out') = self->conditions->find(#num);
			return(#out);
		/define_tag;
		
		define_tag('getalert', -req='num');
			local('out') = self->alerts->find(#num);
			return(#out);
		/define_tag;
		
		define_tag('getdata', -req='methodname', -copy);
			params->size > 1 ? self->setparams(params);
			!self->checkparams ? return('Required parameters are missing.');
			
			local('method') = @self->methods->find(#methodname);
			local('methodexe') = @#method->find('methodexe');
			local('url') = 'http://' + self->key + self->baseurl + #methodexe;
			local('getparams') = #method->find('getparams');
			local('returnvalues') = #method->find('returnvalues');
			local('out') = map;
				
			iterate(self->required, local('i'));		
				#getparams->find(#i)->size ? #getparams->find(#i)->first->second = self->#i;
			/iterate;

			// manually build query string because some params are not name/value pairs
			local('querystring') = string;			
			iterate(#getparams, local('i'));
				#querystring += (#i->isa('pair') ? #i->first + '=' + #i->second | #i) + '&';
			/iterate;
			#querystring->removetrailing('&');		
			#url += '?' + #querystring;
		
			protect;
				local('data') = include_url(
					#url,
					-timeout=10
				)->exportstring('ISO-8859-1')->split('|');
				
				#data->last == '' ? #data->removelast;
				
				if( (: 'getliveweather', 'gettwodayforecast', 'getthreedayforecast') >> #methodname);
					iterate(#returnvalues, local('i'));
						#out->insert(#i = #data->get(loop_count));
					/iterate;
				
				else( (: 'getstations', 'getalerts') >> #methodname);
					// separate first three return values from the rest
					local('meta') = map;
					
					iterate(#returnvalues, local('i'));
						#meta->insert(#i = #data->get(loop_count));
						loop_count == 3 ? loop_abort;
					/iterate;
					
					loop(3);
						#data->removefirst;
						#returnvalues->removefirst;
					/loop;
					
					local('itemdata' = map,);
					local('results') = array;
					
					iterate(#data, local('i'));
						local('getme') = loop_count % #returnvalues->size;
						#getme == 0 ? #getme = #returnvalues->size;
						#itemdata->insert(#returnvalues->get(#getme) = #i);
						
						if(#getme == #returnvalues->size);
							#results->insert(#itemdata);
							#itemdata = map;
						/if;
					/iterate;
					
					#out = #meta;
					#out->insert('Results' = #results);
				/if;
				
				return(#out);
			
				handle_error;
					local('err') = (#data->size ? #data | err_msg);
					return(#err);
				/handle_error;
			/protect;
		/define_tag;
		
		define_tag('_unknowntag');
			if(self->'methods'->keys >> tag_name);
				local('out') = self->getdata(tag_name);
			else(self->properties->first >> tag_name);
				local('out') = @self->properties->first->find(tag_name);
			else;
				local('out') = null;
			/if;
			
			return(#out);
		/define_tag;
	/define_type;

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