forked from NobyDa/Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
41 lines (39 loc) · 1.76 KB
/
weather.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
const lang = "en"
var lat_lon = "21.14874994081167,106.0631039005945"
var api = "d61d56e7025c803083cb4e4d4513d1a3"
async function launch() {
await weather();
$done();
}
launch()
function weather() {
let info = {
url: "https://api.darksky.net/forecast/" + api + "/" + lat_lon + "?lang=" + lang + "&units=si&exclude=currently,minutely", //?lang=en&units=si
headers: {},
}
$httpClient.get(info, async function (error, response, data) {
if (error) {
console.log(error);
$notification.post("Dark Sky", lat_lon + 'bad connection', error);
} else {
var obj = JSON.parse(data);
console.log(obj);
var hour_summary = obj.hourly.summary;
var icon_text = obj.hourly.icon;
var icon = "❓"
if (icon_text == "clear-day") icon = "☀️";
if (icon_text == "partly-cloudy-day") icon = "🌤";
if (icon_text == "cloudy") icon = "☁️";
if (icon_text == "rain") icon = "🌧";
if (icon_text == "snow") icon = "☃️";
if (icon_text == "sleet") icon = "🌨";
if (icon_text == "wind") icon = "🌬";
if (icon_text == "fog") icon = "🌫";
if (icon_text == "partly-cloudy-night") icon = "🌑";
if (icon_text == "clear-night") icon = "🌑";
var daily_prec_chance = obj.daily.data[0].precipProbability;
var daily_maxtemp = obj.daily.data[0].temperatureMax;
var daily_mintemp = obj.daily.data[0].temperatureMin;
$notification.post("Dark Sky", icon + " " +Math.round(daily_mintemp) + " - " + Math.round(daily_maxtemp) + " ☔️ " + (Number(daily_prec_chance) * 100).toFixed(1)+ "%", hour_summary); }
});
}