From 4e86816d379ebf9d34e490714c8c88340f24c33b Mon Sep 17 00:00:00 2001 From: onoc1yn <77744674+onoc1yn@users.noreply.github.com> Date: Tue, 9 Feb 2021 11:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0=E5=A4=A9?= =?UTF-8?q?=E6=B0=94=E7=BB=84=E4=BB=B6=E9=83=A8=E5=88=86=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=8D=A2ipping=20API=20(#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- list.json | 6 +++--- videodl.py | 2 +- weather.py | 53 ++++++++++++++++++++++++++++++++++++++-------------- xtao-some.py | 6 ++---- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/list.json b/list.json index b05cad0..18d36d2 100644 --- a/list.json +++ b/list.json @@ -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", diff --git a/videodl.py b/videodl.py index 29bc661..8f45d02 100644 --- a/videodl.py +++ b/videodl.py @@ -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): diff --git a/weather.py b/weather.py index 44baf23..28e875f 100644 --- a/weather.py +++ b/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 - 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"]) - 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 - ) - await context.edit(res) - else: - await context.edit("出错了呜呜呜 ~ 无法访问到 openweathermap.org 。") \ No newline at end of file + 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 = "{} {}{} 💨{} {}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) + if req.status_code == 404: + await context.edit("出错了呜呜呜 ~ 无效的城市名,请使用拼音输入 ~ ") + return + except Exception: + await context.edit("出错了呜呜呜 ~ 无法访问到 openweathermap.org 。") diff --git a/xtao-some.py b/xtao-some.py index 5843a1b..a53d5b5 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -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':