forked from nzw9314/QuantumultX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather_dark.js
62 lines (55 loc) · 2.55 KB
/
weather_dark.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
var api = "adff46a828dcf7e9686aa52170a1db8a";
//dark sky api: https://darksky.net/dev
var api_aqi = "dc9f948c8d9a8a1f10c2bc5bba60c4dd2e0dec4a"
//aqi api: http://aqicn.org/data-platform/token/#/
var lang = "zh"
var lat_lon = "30.63960103422673,114.8629822119679"
var lat_lon_1 = lat_lon.replace(/,/, ";")
//有问题请通过Telegram反馈 https://t.me/Leped_Bot
//clear-day, partly-cloudy-day, cloudy, clear-night, rain, snow, sleet, wind, fog, or partly-cloudy-night
//☀️🌤⛅️🌥☁️🌦🌧⛈🌩🌨❄️💧💦🌫☔️☂️ ☃️⛄️
function weather() {
var wurl = {
url: "https://api.darksky.net/forecast/" + api + "/" + lat_lon + "?lang=" + lang + "&units=si&exclude=currently,minutely",
};
$task.fetch(wurl).then(response => {
var obj = JSON.parse(response.body);
//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;
aqi(icon, daily_mintemp, daily_maxtemp, daily_prec_chance, hour_summary);
}, reason => {
$notify("Dark Sky", lat_lon + '信息获取失败', reason.error);
});
}
function aqi(icon, daily_mintemp, daily_maxtemp, daily_prec_chance, hour_summary){
let aqi = {
url: "https://api.waqi.info/feed/geo:" + lat_lon_1 + "/?token=" + api_aqi,
headers: {},
}
$task.fetch(aqi).then(response => {
var obj1 = JSON.parse(response.body);
//console.log(obj1);
var aqi = obj1.data.aqi;
var loc = obj1.data.city.name;
loc = loc.split(",")[1];
$notify(loc, icon + " " + Math.round(daily_mintemp) + " - " + Math.round(daily_maxtemp) + "°C ☔️ " + (Number(daily_prec_chance) * 100).toFixed(1) + "%" + " 😷 " + aqi, hour_summary);
}, reason => {
$notify("Aqicn.org", lat_lon + '信息获取失败', reason.error);
});
}
weather()