Login   Register  
Icontem

File: demos/sqlike.html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tom Schaefer  >  Wunderground Weather API  >  demos/sqlike.html  >  Download  
File: demos/sqlike.html
Role: Example script
Content type: text/plain
Description: how query web response and print out a simple result table without server support
Class: Wunderground Weather API
Retrieve weather information with Wunderground API
Author: By
Last change:
Date: 2013-01-05 03:13
Size: 1,884 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Simple HTML RESULT TABLE</title>
<script type="text/javascript" src="../wunderground.js"></script>
<script type="text/javascript" src="http://www.thomasfrank.se/SQLike/js/SQLike.js"></script>
<script type="text/javascript">
htmlTable=function(json){
	if(!json){return};
	var x,header="",content="", colNames={},colAlign={};
	for(var i=0;i<json.length;i++){
		for(var j in json[i]){
			colNames[j]=1
			json[i][j]==json[i][j]/1 && (colAlign[j]=1)
		}
	}
	for(var i=0;i<json.length;i++){
		content+='<tr>';
		for(var j in colNames){
			if(!i){
				header+='<td style="'+(colAlign[j]?'text-align:right;':'')+'background:#666;color:#fff"><b>'+j+'</b></td>'
			};
			content+='<td style="background:'+(i%2==0?'#ddd':'#fff')+'" '+(colAlign[j]?'align="right"':'')+'>'+(json[i][j]+"").replace(/ /g,'&nbsp;')+'</td>'
		};
		content+='</tr>'
	}
	x='<table cellspacing=1 cellpadding=3 border=0 width="710"><tr>'+
		header+'</tr>'+content+'</table>';
	return x
};
</script>
<script type="text/javascript">

var w = new wunderground({
	service: "layerradar",
	options: {
		minlat: 50, maxlat:54
	},
	type: "CityCountry",
	params:["Erftstadt", "Germany"],
	culture: "DE",
	apikey: "--your api key here--"
});
w.getData(function(data){
	var dataTable = data.response.results	
	var rs=SQLike.q({
		Select: ['*'],
		From: dataTable,
		OrderBy: ['city','|desc|']
	});
	var tbl=htmlTable(rs);
	function createDiv(html){ 
		var _body = document.getElementsByTagName('body') [0];
		var _div = document.createElement('div');
		_div.innerHTML=html;
		_body.appendChild(_div);
	}
	createDiv(tbl);
});


</script>
</head>
<body>

</body>
</html>