-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetWeather.js
More file actions
72 lines (53 loc) · 2.04 KB
/
getWeather.js
File metadata and controls
72 lines (53 loc) · 2.04 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
$(document).ready(function() {
// Set the default zip to SF
var defaultZip = 94110;
// Set the zip to default
var zip = defaultZip;
var currentWeather;
var conditions;
var wpc;
// 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"
currentWeather = json.response.ob;
// Save the weather description in a variable
conditions = currentWeather.weather.toLowerCase();
// Save the weather code in a variable
wpc = currentWeather.weatherPrimaryCoded.split(':');
// 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;
// Default
default:
$('#main').addClass('default');
}
// Display current temp and ob
$('#temp').html(currentWeather.tempF + '\u00B0');
$('#conditions').html(conditions);
} else {
alert('Unable to load current conditions: ' + json.error.description);
}
}
});
});