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 pathWeatherCard.lua
101 lines (101 loc) · 3.55 KB
/
WeatherCard.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function ReceiveFriendMsg(CurrentQQ, data)
log.notice("From Lua Log ReceiveFriendMsg %s", CurrentQQ)
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
log.notice("From Lua Log tianqi ReceiveGroupMsg %s", CurrentQQ)
if string.find(data.Content, "天气i") then
keyWord = data.Content:gsub("天气i", "")
if keyWord == "" then
return 1
end
response, error_message =
http.request(
"GET",
"https://geoapi.heweather.net/v2/city/lookup?location=" ..url_encode(keyWord).. "&key=95f5b0cfd4184ee2bfebdb3492ebb293"
)
local html1 = response.body
local c = json.decode(html1)
---air start
response, error_message =
http.request(
"GET",
"https://devapi.heweather.net/v7/air/now?location=" ..c.location[1].id.. "&key=95f5b0cfd4184ee2bfebdb3492ebb293"
)
local html3 = response.body
local air = json.decode(html3)
---air end
response, error_message =
http.request(
"GET",
"https://devapi.heweather.net/v7/weather/3d?location=" ..c.location[1].id.. "&key=95f5b0cfd4184ee2bfebdb3492ebb293"
)
local html2 = response.body
local j = json.decode(html2)
--- type start
if string.find(j.daily[1].textDay, "晴") then
tp = "201"
elseif string.find(j.daily[1].textDay, "多云") then
tp = "202"
elseif string.find(j.daily[1].textDay, "雪") then
tp = "205"
elseif string.find(j.daily[1].textDay, "雾") then
tp = "206"
elseif string.find(j.daily[1].textDay, "霾") then
tp = "208"
elseif string.find(j.daily[1].textDay, "雨") then
tp = "204"
elseif string.find(j.daily[1].textDay, "尘") then
tp = "207"
else
tp = "203"
end
--- type end
ApiRet =
Api.Api_SendMsg(
CurrentQQ,
{
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "JsonMsg",
groupid = 0,
content = string.format(
[[{"app":"com.tencent.weather","desc":"天气","view":"RichInfoView","ver":"1.0.0.217","prompt":"[应用]和风天气","meta":{"richinfo":{"adcode":"%s","air":"%s","city":"%s","date":"%s月%s日","max":"%s","min":"%s","ts":"1554951408","type":"%s","wind":"%s"}},"config":{"forward":1,"autosize":1,"type":"card"}}]],
c.location[1].id,
air.now.aqi,
c.location[1].name,
os.date('!%m'),
os.date('!%d'),
j.daily[1].tempMax,
j.daily[1].tempMin,
tp,
j.daily[1].windSpeedDay),
atUser = 0
}
)
log.notice("From Lua SendMsg Ret-->%d", ApiRet.Ret)
end
return 1
end
function ReceiveEvents(CurrentQQ, data, extData)
return 1
end
function url_encode(str)
if (str) then
str = string.gsub(str, "\n", "\r\n")
str =
string.gsub(
str,
"([^%w ])",
function(c)
return string.format("%%%02X", string.byte(c))
end
)
str = string.gsub(str, " ", "+")
end
return str
end