mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-25 12:37:49 +00:00
weather resou 支持 Pyro (#11)
Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
This commit is contained in:
parent
ddc3e2d081
commit
ae2bd7149b
20
list.json
20
list.json
@ -129,6 +129,26 @@
|
||||
"supported": true,
|
||||
"des-short": "查询域名whois信息",
|
||||
"des": "查看域名是否已被注册、注册日期、过期日期、域名状态、DNS解析服务器等。"
|
||||
},
|
||||
{
|
||||
"name": "weather",
|
||||
"version": "1.111",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "3.1 kb",
|
||||
"supported": true,
|
||||
"des-short": "查询天气。",
|
||||
"des": "这个人很懒,什么都没有留下。"
|
||||
},
|
||||
{
|
||||
"name": "resou",
|
||||
"version": "1.221",
|
||||
"section": "daily",
|
||||
"maintainer": "KorenKrita、xtaodada、monsterxcn",
|
||||
"size": "2.5 kb",
|
||||
"supported": true,
|
||||
"des-short": "微博,知乎,抖音实时热搜。",
|
||||
"des": "命令:wbrs,zhrs,dyrs。"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
59
resou/main.py
Normal file
59
resou/main.py
Normal file
@ -0,0 +1,59 @@
|
||||
from pyrogram import Client
|
||||
from json.decoder import JSONDecodeError
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.utils import Message, client
|
||||
|
||||
|
||||
@listener(command="zhrs",
|
||||
description="知乎热搜。")
|
||||
async def zhrs(_: Client, message: Message):
|
||||
req = await client.get("https://tenapi.cn/zhihuresou")
|
||||
if req.status_code == 200:
|
||||
try:
|
||||
data = req.json()
|
||||
except JSONDecodeError:
|
||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
||||
return
|
||||
res = '知乎实时热搜榜:\n'
|
||||
for i in range(0, 10):
|
||||
res += f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["query"]}</a>」'
|
||||
await message.edit(res)
|
||||
else:
|
||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
||||
|
||||
|
||||
@listener(command="wbrs",
|
||||
description="微博热搜。")
|
||||
async def wbrs(_: Client, message: Message):
|
||||
req = await client.get("https://tenapi.cn/resou")
|
||||
if req.status_code == 200:
|
||||
try:
|
||||
data = req.json()
|
||||
except JSONDecodeError:
|
||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
||||
return
|
||||
res = '微博实时热搜榜:\n'
|
||||
for i in range(0, 10):
|
||||
res += f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["name"]}</a>」 ' \
|
||||
f'热度:{data["list"][i]["hot"]}'
|
||||
await message.edit(res)
|
||||
else:
|
||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
||||
|
||||
|
||||
@listener(command="dyrs",
|
||||
description="抖音热搜。")
|
||||
async def dyrs(_: Client, message: Message):
|
||||
req = await client.get("https://tenapi.cn/douyinresou")
|
||||
if req.status_code == 200:
|
||||
try:
|
||||
data = req.json()
|
||||
except JSONDecodeError:
|
||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
||||
return
|
||||
res = '抖音实时热搜榜:\n'
|
||||
for i in range(0, 10):
|
||||
res += f'\n{i + 1}.「{data["list"][i]["name"]}」 热度:{data["list"][i]["hot"]}'
|
||||
await message.edit(res)
|
||||
else:
|
||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
77
weather/main.py
Normal file
77
weather/main.py
Normal file
@ -0,0 +1,77 @@
|
||||
import datetime
|
||||
from pyrogram import Client
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.utils import Message, client
|
||||
|
||||
icons = {
|
||||
"01d": "🌞",
|
||||
"01n": "🌚",
|
||||
"02d": "⛅️",
|
||||
"02n": "⛅️",
|
||||
"03d": "☁️",
|
||||
"03n": "☁️",
|
||||
"04d": "☁️",
|
||||
"04n": "☁️",
|
||||
"09d": "🌧",
|
||||
"09n": "🌧",
|
||||
"10d": "🌦",
|
||||
"10n": "🌦",
|
||||
"11d": "🌩",
|
||||
"11n": "🌩",
|
||||
"13d": "🌨",
|
||||
"13n": "🌨",
|
||||
"50d": "🌫",
|
||||
"50n": "🌫",
|
||||
}
|
||||
|
||||
|
||||
def timestamp_to_time(timestamp, timeZoneShift):
|
||||
timeArray = datetime.datetime.utcfromtimestamp(timestamp) + datetime.timedelta(seconds=timeZoneShift)
|
||||
return timeArray.strftime("%H:%M")
|
||||
|
||||
|
||||
def calcWindDirection(windDirection):
|
||||
dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
|
||||
ix = round(windDirection / (360. / len(dirs)))
|
||||
return dirs[ix % len(dirs)]
|
||||
|
||||
|
||||
@listener(command="weather",
|
||||
description="查询天气",
|
||||
parameters="<城市>")
|
||||
async def weather(_: Client, message: Message):
|
||||
of not message.arguments:
|
||||
return await message.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||
try:
|
||||
req = await client.get(
|
||||
"http://api.openweathermap.org/data/2.5/weather?appid=973e8a21e358ee9d30b47528b43a8746&units=metric&lang"
|
||||
"=zh_cn&q=" + message.arguments)
|
||||
if req.status_code == 200:
|
||||
data = req.json()
|
||||
cityName = "{}, {}".format(data["name"], data["sys"]["country"])
|
||||
timeZoneShift = data["timezone"]
|
||||
temp_Max = round(data["main"]["temp_max"], 2)
|
||||
temp_Min = round(data["main"]["temp_min"], 2)
|
||||
pressure = data["main"]["pressure"]
|
||||
humidity = data["main"]["humidity"]
|
||||
windSpeed = data["wind"]["speed"]
|
||||
windDirection = calcWindDirection(data["wind"]["deg"])
|
||||
sunriseTimeunix = data["sys"]["sunrise"]
|
||||
sunriseTime = timestamp_to_time(sunriseTimeunix, timeZoneShift)
|
||||
sunsetTimeunix = data["sys"]["sunset"]
|
||||
sunsetTime = timestamp_to_time(sunsetTimeunix, timeZoneShift)
|
||||
fellsTemp = data["main"]["feels_like"]
|
||||
tempInC = round(data["main"]["temp"], 2)
|
||||
tempInF = round((1.8 * tempInC) + 32, 2)
|
||||
icon = data["weather"][0]["icon"]
|
||||
desc = data["weather"][0]["description"]
|
||||
res = "{} {}{} 💨{} {}m/s\n大气🌡 {}℃ ({}℉) 💦 {}% \n体感🌡 {}℃\n气压 {}hpa\n🌅{} 🌇{} ".format(
|
||||
cityName, icons[icon], desc, windDirection, windSpeed, tempInC, tempInF, humidity, fellsTemp, pressure,
|
||||
sunriseTime, sunsetTime
|
||||
)
|
||||
await message.edit(res)
|
||||
if req.status_code == 404:
|
||||
await message.edit("出错了呜呜呜 ~ 无效的城市名,请使用拼音输入 ~ ")
|
||||
return
|
||||
except Exception:
|
||||
await message.edit("出错了呜呜呜 ~ 无法访问到 openweathermap.org 。")
|
Loading…
Reference in New Issue
Block a user