mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-24 22:33:41 +00:00
✨ 增加天气组件部分功能,更换ipping API (#108)
* Add: Weather, more data to parse. * Add: Weather, more data to parse. * Fix: ipping API * Fix: ipping API * Fix: localtime 导致的计算问题 * Fix: timezone for sunrise and sunset. * Fix: pytube lib known issues.
This commit is contained in:
parent
c00bfdca1f
commit
4e86816d37
@ -52,17 +52,17 @@
|
||||
},
|
||||
{
|
||||
"name": "weather",
|
||||
"version": "1.0",
|
||||
"version": "1.1",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "1.5 kb",
|
||||
"size": "2.9 kb",
|
||||
"supported": true,
|
||||
"des-short": "查询天气。",
|
||||
"des": "这个人很懒,什么都没有留下。"
|
||||
},
|
||||
{
|
||||
"name": "xtao-some",
|
||||
"version": "1.12",
|
||||
"version": "1.13",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "18.8 kb",
|
||||
|
@ -33,7 +33,7 @@ async def vdl(context):
|
||||
try:
|
||||
from pytube import YouTube
|
||||
except ImportError:
|
||||
await context.edit('(`pytube3`支持库未安装,YouTube视频无法下载\n请使用 `-sh` `pip3` `install` `pytube3` 安装,或自行ssh安装)')
|
||||
await context.edit('`pytube`支持库未安装,YouTube视频无法下载\n请使用 `-sh pip3 install --user git+https://github.com/nficano/pytube` 安装,或自行ssh安装\n\n已安装过 `pytube3` 的用户请使用 `-sh pip3 uninstall pytube3 -y` 进行卸载')
|
||||
return
|
||||
url = url.replace('www.youtube.com/watch?v=', 'youtu.be/')
|
||||
if not await youtube_dl(url, context, reply_id):
|
||||
|
31
weather.py
31
weather.py
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import datetime
|
||||
from requests import get
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.utils import obtain_message
|
||||
@ -24,6 +25,14 @@ icons = {
|
||||
"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(is_plugin=True, outgoing=True, command="weather",
|
||||
description="查询天气",
|
||||
parameters="<城市>")
|
||||
@ -34,17 +43,33 @@ async def weather(context):
|
||||
except ValueError:
|
||||
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||
return
|
||||
try:
|
||||
req = get("http://api.openweathermap.org/data/2.5/weather?appid=973e8a21e358ee9d30b47528b43a8746&units=metric&lang=zh_cn&q=" + message)
|
||||
if req.status_code == 200:
|
||||
data = json.loads(req.text)
|
||||
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 = "{}\n🌡{}℃ ({}F)\n{} {}".format(
|
||||
cityName, tempInC, tempInF, icons[icon], desc
|
||||
res = "{} {}{} 💨{} {}m/s\n大气🌡 {}℃ ({}℉) 💦 {}% \n体感🌡 {}℃\n气压 {}hpa\n🌅{} 🌇{} ".format(
|
||||
cityName, icons[icon], desc, windDirection, windSpeed, tempInC, tempInF, humidity, fellsTemp, pressure, sunriseTime, sunsetTime
|
||||
)
|
||||
await context.edit(res)
|
||||
else:
|
||||
if req.status_code == 404:
|
||||
await context.edit("出错了呜呜呜 ~ 无效的城市名,请使用拼音输入 ~ ")
|
||||
return
|
||||
except Exception:
|
||||
await context.edit("出错了呜呜呜 ~ 无法访问到 openweathermap.org 。")
|
@ -197,8 +197,7 @@ async def ipping(context):
|
||||
else:
|
||||
url = url.path
|
||||
pinginfo = requests.get(
|
||||
"https://helloacm.com/api/ping/?cached&host=" + url).content.decode(
|
||||
"utf-8")
|
||||
"https://steakovercooked.com/api/ping/?host=" + url).content.decode("utf-8")
|
||||
if pinginfo == 'null':
|
||||
pass
|
||||
elif not pinginfo == 'null':
|
||||
@ -215,8 +214,7 @@ async def ipping(context):
|
||||
await context.edit('没有找到要查询的 ip/域名 ...')
|
||||
return True
|
||||
pinginfo = requests.get(
|
||||
"https://helloacm.com/api/ping/?cached&host=" + url).content.decode(
|
||||
"utf-8")
|
||||
"https://steakovercooked.com/api/ping/?host=" + url).content.decode("utf-8")
|
||||
if pinginfo == 'null':
|
||||
pass
|
||||
elif not pinginfo == 'null':
|
||||
|
Loading…
Reference in New Issue
Block a user