summaryrefslogtreecommitdiff
path: root/AyaBot/plugins/covid19.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-06-06 11:10:49 +0800
committerKyomotoi <[email protected]>2020-06-06 11:10:49 +0800
commit42a5544f676a6260bdea7cd20b19f6956c1759c0 (patch)
tree3e2cf198197f8bc03896049093003a69730a119b /AyaBot/plugins/covid19.py
parentc9611c30255a4d8a1c3e1dca498d4fc963068b04 (diff)
downloadATRI-42a5544f676a6260bdea7cd20b19f6956c1759c0.tar.gz
ATRI-42a5544f676a6260bdea7cd20b19f6956c1759c0.tar.bz2
ATRI-42a5544f676a6260bdea7cd20b19f6956c1759c0.zip
Minor changes to the plugin
Diffstat (limited to 'AyaBot/plugins/covid19.py')
-rw-r--r--AyaBot/plugins/covid19.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/AyaBot/plugins/covid19.py b/AyaBot/plugins/covid19.py
new file mode 100644
index 0000000..1c9028c
--- /dev/null
+++ b/AyaBot/plugins/covid19.py
@@ -0,0 +1,53 @@
+import json
+import requests
+from nonebot import on_command, CommandSession
+
+
+# 国外版 数据更新非常及时
+# 必须挂木弟子
+# 成功把之前的屎优化了!OHHHHHHHHHHHH
+# 如需使用国内版,请查看下面的链接,下载后与这个文件替换
+# https://github.com/Kyomotoi/covid19/tree/master/Domestic
+
+
+
+url = "https://covid-19-coronavirus-statistics.p.rapidapi.com/v1/total"
+
+
+LIST = """截至: {lastChecked}
+国家: {location}
+已治愈: {recovered}
+已经死亡: {deaths}
+总感染数: {confirmed}
+现存感染人数: {nowConfirmed}
+最后检查时间: {lastReported}"""
+
+
+@on_command('covid19', aliases=['疫情', '疫情查询', '疫情情况'], only_to_me=False)
+async def covid19(session: CommandSession):
+ country = session.get('country', prompt='请用Eng键入需要查询的国家(例:China)')
+ await session.send('开始搜寻...\n如返回国名为Global的则为提供的国家名有问题,必须为英文全称')
+ try:
+ querystring = {"country":"cy"}
+ querystring["country"] = country
+ print(querystring)
+ headers = {
+ 'x-rapidapi-host': "covid-19-coronavirus-statistics.p.rapidapi.com",
+ 'x-rapidapi-key': "a852be0d03msh8bd4299fe71bfeep100861jsn185ea925449c"
+ }
+ response = requests.request("GET", url, headers=headers, params=querystring)
+ # print(response.text)
+ html = response.text
+ c19 = json.loads(html)
+ await session.send(LIST.format(
+ lastChecked=c19["data"]["lastChecked"],
+ location=c19["data"]["location"],
+ recovered=c19["data"]["recovered"],
+ deaths=c19["data"]["deaths"],
+ confirmed=c19["data"]["confirmed"],
+ nowConfirmed=c19["data"]["confirmed"] - c19["data"]["deaths"] - c19["data"]["recovered"],
+ lastReported=c19["data"]["lastReported"],
+ )
+ )
+ except:
+ await session.send('搜索出问题了呢,重新试试?') \ No newline at end of file