-
Notifications
You must be signed in to change notification settings - Fork 0
/
darksky.js
43 lines (30 loc) · 1.11 KB
/
darksky.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
var api = require('zenircbot-api');
var darksky = require('darksky');
var zen = new api.ZenIRCBot();
var config = api.load_config('./darksky/config.json');
var client = new darksky.Client(config.api_key);
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.substring(1);
}
var lastPrecipitating = null;
function check() {
client.brief_forecast(config.lat, config.lng, function(err, data) {
if (err) {
console.error(err);
}
var forecast = JSON.parse(data);
// print the current conditions if the isPrecipitation has changed
if (lastPrecipitating != forecast.isPrecipitating) {
lastPrecipitating = forecast.isPrecipitating;
var msg = "[Weather] " + capitalize(forecast.currentSummary);
// if Dark Sky provides it, add the minutes until change to the message
if (forecast.minutesUntilChange > 0) {
msg += " for the next " + forecast.minutesUntilChange + " minutes.";
}
msg += " (" + forecast.currentTemp + "°F)"
zen.send_privmsg(config.channel, msg);
}
setTimeout(check, forecast.checkTimeout * 1000);
});
}
check();