562
| <![CDATA[<script>
//TRADU��O
var ArrCondition = Array('clear-night', 'clear', 'cloudy', 'drizzle', 'fair-night', 'fair', 'fog', 'foggy', 'haze-night', 'haze', 'isolated-thunderstorms-night', 'isolated-thunderstorms', 'mostly-cloudy-night', 'mostly-cloudy', 'mostly-sunny', 'partly-cloudy-night', 'partly-cloudy', 'partly-sunny', 'rain', 'scattered-showers-night', 'scattered-showers', 'scattered-thunderstorms-night', 'scattered-thunderstorms', 'showers-night', 'showers', 'sunny', 'thundershowers', 'thunderstorms', 'thunder', 'thunder-in-the-vicinity', 'wind', 'mostly-clear', 'mostly-clear-night', 'light-rain', 'rain-early', 'clouds', 'showers-early', 'light-drizzle', 'light-rain-with-thunder', 'showers-in-the-vicinity');
var ArrConditionPT = Array('noite limpa', 'céu claro', 'encoberto', 'garoa', 'poucas nuvens', 'poucas nuvens', 'nevoeiro', 'nebuloso', 'neblina', 'neblina', 'trovoadas isoladas', 'trovoadas isoladas', 'parcialmente encoberto', 'parcialmente encoberto', 'sol entre nuvens', 'parcialmente encoberto', 'parcialmente encoberto', 'sol entre nuvens', 'chuva', 'chuvas esparsas', 'chuvas esparsas', 'trovoadas esparsas', 'trovoadas esparsas', 'chuvas esparsas', 'chuvas esparsas', 'ensolarado', 'chuva', 'trovoadas', 'trovoadas', 'trovoadas', 'ventos', 'céu claro', 'céu claro', 'chuva fraca', 'chuva pela manhã;', 'nuvens', 'chuva fraca', 'chuva fraca', 'chuva fraca com trovoadas', 'encoberto');
function ucFirst(string) {
return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
}
function findImg(items, hora) {
var lixo = Array('am', 'pm');
var code = -1;
items = items.split('/');
items = items[0];
var temp = items.toLowerCase().replace(lixo, '');
temp = $.trim(temp).replace(' ', '-');
//Pesquisa se tem �cone para a noite
if(hora != '') {
if((hora < 6)||(hora > 18)) {
code = $.inArray(temp + '-night', ArrCondition);
if(code === false) {
code = -1;
}
}
}
//N�o tem �cone para a noite
if(code < 0) {
code = $.inArray(temp, ArrCondition);
if(code === false) {
code = -1;
}
}
return code;
}
function FtoC(v) {
var val = parseFloat(v);
var val = (v - 32) / 9 * 5;
return Math.round(val);
}
// $(function() {
// // var query = escape("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='Sananduva, RS')"),
// // url = "https://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=?";
// url = "./api/tempo.php";
// $.getJSON(url, function(data) {
// console.log("API Tempo");
// var forecast = JSON.parse(data).forecast[0].high;
// // var condition = data.current_observation.condition;
// console.log(forecast);
// $('#weather-high').html(forecast.high);
// $('#weather-low').html(forecast.low);
// $('#weather-temp').html(condition.temperature);
// var code = findImg(condition.text, 09);
// $('#weather-text').html(ucFirst(ArrConditionPT[code]));
// $('#weather-img').attr('src', 'assets/yahoo-weather/icons/' + ArrCondition[code] + '.png');
// $('#weather-img').attr('alt', ucFirst(ArrConditionPT[code]));
// $('#weather-img').attr('title', ucFirst(ArrConditionPT[code]));
// $('#previsaoJS').show();
// });
// });
$(document).ready(function(){
getDataTempo();
});
function getDataTempo(){
$.ajax({
url: "./api/tempo.php",
type: "GET",
success: function(data){
$('#weather-high').html(JSON.parse(data).forecasts[0].high);
$('#weather-low').html(JSON.parse(data).forecasts[0].low);
$('#weather-temp').html(JSON.parse(data).current_observation.condition.temperature);
var code = findImg(JSON.parse(data).current_observation.condition.text, 09);
$('#weather-text').html(ucFirst(ArrConditionPT[code]));
$('#weather-img').attr('src', 'assets/yahoo-weather/icons/' + ArrCondition[code] + '.png');
$('#weather-img').attr('alt', ucFirst(ArrConditionPT[code]));
$('#weather-img').attr('title', ucFirst(ArrConditionPT[code]));
$('#previsaoJS').show();
},
});
}
</script>]]>
|