-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
65 lines (55 loc) · 1.97 KB
/
demo.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
var Weather = require('./weather');
var DarkSky_Key = '0123456789abcdef9876543210fedcba'; //this is a fake key
var boston = new Weather.service({
provider: 'darksky',
key: DarkSky_Key,
latitude: 42.3601,
longitude: -71.0589,
celsius: false
});
//In this example we're going to wait for the 'ready' event before running the first update.
boston.on('ready', function() {
boston.update(function(err) {
if (err) {
console.log('ERROR: ' + err);
} else {
console.log('\r\n---Boston Weather (DarkSky)---');
printWeather(boston);
}
});
});
boston.on('error', function(err) {
console.log('ERROR with Boston weather lookup: ' + err);
});
var AccuWeather_Key = '0123456789abcdef9876543210fedcba'; //this is a fake key
var houston = new Weather.service({
provider: 'accuweather',
key: AccuWeather_Key,
latitude: 29.7604,
longitude: -95.3698,
celsius: false
});
//if you call the update function before the weather service has loaded it will store
//a reference to the callback and automatically run it when the service is loaded
//so even though we're calling the update() function before the ready event was fired
//this will still work.
houston.update(function(err) {
if (err) {
console.log('ERROR: ' + err);
} else {
console.log('---Houston Weather (AccuWeather)---');
printWeather(houston);
}
});
//This is just a simple function to print some information from a weather service
function printWeather(weather) {
console.log('Last Update: ' + weather.lastUpdate);
console.log('forecastTime: ' + weather.forecastTime);
console.log('Temp: ' + weather.temp);
console.log('Feels like: ' + weather.feelsLike);
console.log('Current Condition: ' + weather.currentCondition);
console.log('Humidity: ' + weather.humidity);
console.log('Sunrise: ' + weather.sunrise);
console.log('Sunset: ' + weather.sunset);
console.log('\r\n');
}