-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
110 lines (85 loc) · 3 KB
/
weather.js
File metadata and controls
110 lines (85 loc) · 3 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$(document).ready(function() {
// Get the current conditions
$.ajax({
url: 'http://api.aerisapi.com/observations/' + zip + ' ?client_id=LI7gJnbLEdzpjWXZzBaMP&client_secret=4wgCjhk2sd0AC0YPbzsnp94X1HaY0EdSocIfwSEw',
dataType: "jsonp",
success: function(json) {
if (json.success) {
// Save the weather objec in variable "currentWeather"
var currentWeather = json.response.ob;
// Save the weather description in a variable
var conditions = currentWeather.weather.toLowerCase();
// Save the weather code in a variable
var wpc = currentWeather.weatherPrimaryCoded;
// Use a switch to set the background based on weather codes
switch (wpc) {
// Clear
case "CL":
$('.main').addClass('sunny');
break;
// Fair + partly cloudy
case "FW":
$('.main').addClass('partly-cloudy');
break;
case "SC":
$('.main').addClass('partly-cloudy');
break;
// Mostly cloudy + cloudy
case "BK":
$('.main').addClass('partly-cloudy');
break;
case "OV":
$('.main').addClass('partly-cloudy');
break;
/*
// Fog
BR Mist
H Haze
F Fog
IF Ice fog
ZF Freezing fog
// Rain
L Drizzle
ZL Freezing drizzle
RW Rain showers
R Rain
ZR Freezing rain
RS Rain/snow mix
// Hail
A Hail
IP Ice pellets / sleet
// Snow
SI Snow/sleet mix
WM Wintry mix
S Snow
SW Snow showers
ZY Freezing spray
// Dust/Sand
BD Blowing dust
BN Blowing sand
// Snow
BS Blowing snow
// Frost
FR Frost
IC Ice crystals
// Smoke
K Smoke
// Thunderstorm
T Thunderstorms
// Volcanic Ash
VA Volcanic ash
// Water spouts
WP Water spouts
// Unkown
UP Unknown Precipitation
*/
}
// Display current temp and conditions
$('#temp').html(currentWeather.tempF + '\u00B0');
$('#conditions').html(conditions);
} else {
alert('Unable to load current conditions: ' + json.error.description);
}
}
});
});