-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather-api-example.html
More file actions
65 lines (57 loc) · 1.72 KB
/
weather-api-example.html
File metadata and controls
65 lines (57 loc) · 1.72 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Weather API Examples</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="js/keys.js"></script>
<script>
"use strict";
// convert API date/time response to JS Date Object
// ... new Date(1629461117 * 1000)
$.get('https://api.openweathermap.org/data/2.5/onecall', {
appid: WEATHER_APP_ID,
lat: 29.4252,
lon: -98.4916,
units: 'imperial',
exclude: 'minutely,hourly'
}).done(function(data) {
console.log(data);
console.log(data.daily[0].humidity);
data.daily.forEach(function(day) {
console.log(day.humidity);
});
}).fail(function(error) {
console.log(error);
});
// $.get('https://api.openweathermap.org/data/2.5/onecall', {
// appid: WEATHER_APP_ID,
// lat: 31.7619,
// lon: -106.4850,
// units: 'imperial',
// exclude: 'minutely,hourly' //remember to not include spaces when excluding something
// }).done(function(data) {
// console.log(data);
//
// //this is how you find the humidity for day 1 (which is at index[0])
// console.log(data.daily[0].humidity);
//
// //this is how you find the daily humidity using a forEach
// data.daily.forEach(function(day) {
// console.log(day.humidity);
// });
//
// //this is how you find just the cloud coverage
// console.log(data.current.clouds);
//
// console.log('5 day forecast', data);
//
// //if something fails, we should push out an error message using this code
// }).fail(function(error) {
// console.log(error);
// });
</script>
</body>
</html>