-
Notifications
You must be signed in to change notification settings - Fork 0
/
天气-中央气象台.lua
87 lines (78 loc) · 2.8 KB
/
天气-中央气象台.lua
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- nmc/天气
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function startswith(str, Start)
return string.sub(str, 1, string.len(Start)) == Start
end
function getWeather(cityID)
local res, err = http.request('GET', 'http://www.nmc.cn/rest/weather?stationid='..cityID)
if err ~= nil then
return nil
end
local info = json.decode(res.body)
local info_real = info['data']['real']
local info_predict = info['data']['predict']
local real = string.format(
'%s\n气温: %.1f°C %s\n体感温度: %.1f°C\n气温变化: %.1f°C \n空气压力: %.1fhPa\n湿度: %d %%\n降雨量: %dmm\n%s %s\n%s',
info_real['station']['province']..info_real['station']['city'],
info_real['weather']['temperature'],
info_real['weather']['info'],
info_real['weather']['feelst'],
info_real['weather']['temperatureDiff'],
info_real['weather']['airpressure'],
info_real['weather']['humidity'],
info_real['weather']['rain'],
info_real['wind']['direct'],
info_real['wind']['power'],
info_real['publish_time']
)
local predict_detail = info_predict['detail']
local predict = string.format(
'%s\n白天: %s°C %s %s%s\n夜间: %s°C %s %s%s',
info_predict['publish_time'],
predict_detail[1]['day']['weather']['temperature'],
predict_detail[1]['day']['weather']['info'],
predict_detail[1]['day']['wind']['direct'],
predict_detail[1]['day']['wind']['power'],
predict_detail[1]['night']['weather']['temperature'],
predict_detail[1]['night']['weather']['info'],
predict_detail[1]['night']['wind']['direct'],
predict_detail[1]['night']['wind']['power']
)
return real..'\n----------\n'..predict
end
function ReceiveGroupMsg(CurrentQQ, data)
if data.FromUserId == tonumber(CurrentQQ) then
return 1
end
if startswith(data.Content, 'nmc') or startswith(data.Content, '天气') then
local city = data.Content:gsub('nmc', ''):gsub('天气', '')
local f, _ = io.open('./Plugins/stationID.json', "r")
local content = f:read("*all")
f:close()
local ID_Data = json.decode(content)
local cityID = ID_Data[city]
if cityID then
Api.Api_SendMsg(
CurrentQQ,
{
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "TextMsg",
groupid = 0,
content = getWeather(cityID),
atUser = 0
}
)
return 2
end
end
return 1
end
function ReceiveFriendMsg(CurrentQQ, data)
return 1
end
function ReceiveEvents(CurrentQQ, data, extData)
return 1
end