-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (52 loc) · 2.9 KB
/
script.js
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
63
64
65
66
67
68
69
70
71
72
function getweather(a) {
$URL = "https://api.openweathermap.org/data/2.5/weather?q=" + a + "&appid=4baa298ea0cc0c7bcb2f8de5d304cf50&units=metric";
$.getJSON($URL, function( data ) {
weather_desc = JSON.stringify(data.weather[0].main);
weather_temp = JSON.stringify(data.main.temp);
weather_tmin = JSON.stringify(data.main.temp_min);
weather_tmin = parseFloat(weather_tmin-2).toFixed(0);
weather_tmax = JSON.stringify(data.main.temp_max);
weather_tmax = parseFloat(weather_tmax+2).toFixed(0);
weather_humi = JSON.stringify(data.main.humidity);
weather_pres = JSON.stringify(data.main.pressure);
weather_feli = JSON.stringify(data.main.feels_like);
sunrise = JSON.stringify(data.sys.sunrise);
sunrise = new Date(sunrise*1000);
sunrise = sunrise.toString();
sunrise = sunrise.slice(15, 21);
sunset = JSON.stringify(data.sys.sunset);
sunset = new Date(sunset*1000);
sunset = sunset.toString();
sunset = sunset.slice(15, 21);
var iconcode = data.weather[0].icon;
hr.style.display = "";
hr2.style.display = "";
icon.style.display = "";
separe.style.display = "";
separe2.style.display = "";
$('#city').text(a);
$('#weather_tmin').text(Math.round(weather_tmin * 2) / 2 + "°");
$('#weather_tmax').text(" " + Math.round(weather_tmax * 2) / 2 + "°");
$('#weather_temp').text(Math.round(weather_temp * 2) / 2 + "°");
weather_desc = weather_desc.slice(1, weather_desc.length - 1)
$('#weather_desc').text(weather_desc);
$('#weather_hum').html('Humidity: <span style="font-family: ' + 'Comfortaa' + ', cursive;color:black;">' + weather_humi + '%</span>');
$('#weather_hum').show();
$('#weather_pres').html('Pressure: <span style="font-family: ' + 'Comfortaa' + ', cursive;color:black;">' + weather_pres + 'hPa</span>');
$('#weather_pres').show();
$('#weather_feli').html('Feels Like: <span style="font-family: ' + 'Comfortaa' + ', cursive;color:black;">' + Math.round(weather_temp * 2) / 2 + '°</span>');
$('#weather_feli').show();
$('#sunrise').html('Sunrise: <span style="color:black;">' + sunrise + '</span>');
$('#sunrise').show();
$('#sunset').html('Sunset: <span style="color:black;">' + sunset + '</span>');
$('#sunset').show();
var iconurl = "https://openweathermap.org/img/w/" + iconcode + ".png";
var iconfield = document.getElementById('wicon');
if(iconcode == "01d")
iconfield.classList.add("sunnyanimation");
else
iconfield.classList.remove("sunnyanimation");
$('#wicon').attr('src', iconurl);
searchbox = document.getElementById("a").value = "";
});
}