This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCYWeather.lua
52 lines (52 loc) · 2.23 KB
/
CYWeather.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
---数据来源自彩云天气®,需要请自行获取APIKey
---最终国家基本站点数据请以中央气象台NMC发布数据为准
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function ReceiveFriendMsg(CurrentQQ, data)
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if string.find(data.Content, "查天气") then
keyWord = data.Content:gsub("查天气", "")
if keyWord == "" then
return 1
end
response, error_message =
http.request(
"GET",
"http://json.xinmoe.cn/geocode.json"
)
local geo = response.body
local geojs = json.decode(geo)
response, error_message =
http.request(
"GET",
"http://api.caiyunapp.com/v2.5/Put Your Key/weather.json?adcode=" ..geojs[keyWord].district_geocode.. "&unit=metric:v2"
)
local html = response.body
local a = json.decode(html)
humidity = a.result.realtime.humidity * 100
cloud = a.result.realtime.cloudrate * 100
temp = a.result.realtime.temperature
temp2 = a.result.realtime.apparent_temperature
wind = a.result.realtime.wind.speed / 3.6
vis = a.result.realtime.visibility
press = a.result.realtime.pressure / 100
time = a.server_time
local t = os.date("%Y年%m月%d日%H:%M:%S",time) ---数据获取时间戳
ApiRet =
Api.Api_SendMsgV2(
CurrentQQ,
{
ToUserUid = data.FromGroupId,
SendToType = 2,
SendMsgType = "TextMsg",
groupid = 0,
Content = "DataTime:" ..t.. " - " ..keyWord.. "\n气温:" ..temp.. "℃ & 体感温度:" ..string.format("%.1f",temp2).. "℃\n湿度:" ..humidity.. "%\n能见度:" ..vis.. "km\n云量:" ..cloud.. "%\n风:" ..string.format("%.1f",a.result.realtime.wind.direction).. "° & " ..string.format("%.1f",wind).. "m/s\n站点气压:" ..string.format("%.1f",press).. "hPa\n------------\n" ..a.result.forecast_keypoint.. ""
}
)
end
return 1
end