Merge pull request #9 from Si-Huan/master

update
This commit is contained in:
weilinfox 2020-09-13 22:02:51 +08:00 committed by GitHub
commit ceb4306548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 5 deletions

3
.gitignore vendored
View file

@ -5,4 +5,5 @@ config.py
.idea
test.py
push.cmd
data/pcr/char.list
data/pcr/char.list
venv

21
req.txt
View file

@ -1,31 +1,52 @@
astroid==2.3.3
autopep8==1.5
backcall==0.2.0
certifi==2019.11.28
chardet==3.0.4
Click==7.0
decorator==4.4.2
entrypoints==0.3
flake8==3.7.9
Flask==1.1.1
idna==2.9
importlib-metadata==1.5.0
inflect==4.1.0
ipykernel==5.3.4
ipython==7.18.1
ipython-genutils==0.2.0
isort==4.3.21
itsdangerous==1.1.0
jaraco.itertools==5.0.0
jedi==0.17.2
Jinja2==2.11.1
jupyter-client==6.1.7
jupyter-core==4.6.3
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==8.2.0
parso==0.7.1
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.7
ptyprocess==0.6.0
pycodestyle==2.5.0
pydub==0.24.1
pyflakes==2.1.1
Pygments==2.7.0
pylint==2.4.4
python-dateutil==2.8.1
pyzmq==19.0.2
redis==3.4.1
requests==2.23.0
six==1.14.0
sxtwl==1.1.0
toml==0.10.1
tornado==6.0.4
traitlets==5.0.4
typed-ast==1.4.1
urllib3==1.25.8
wcwidth==0.2.5
Werkzeug==1.0.0
wolframalpha==4.0.0
wrapt==1.11.2

View file

@ -2,9 +2,6 @@ from worker import emmm
def ZZRouter(data):
if data['post_type'] != 'message' or data['message_type'] != 'group' or data['message'][0] != '/':
return
uid = data['user_id']
gid = data['group_id']
role = data['sender']['role']

View file

@ -4,7 +4,7 @@ import requests
from config import LOLIKEYS
class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 247022495, 474907856]
def GETMSG(self):
keys = LOLIKEYS

56
worker/weather.py Normal file
View file

@ -0,0 +1,56 @@
import random
import requests
import datetime
from zzcore import StdAns
class Ans(StdAns):
"""docstring for Ans"""
def GETMSG(self):
try:
return self.get_weather()
except Exception as e:
return "啊哦,出错了"
def get_weather(self):
ran = random.randint(0, 9999999999)
url = "https://api.caiyunapp.com/v2/Y2FpeXVuIGFuZHJpb2QgYXBp/120.127164,36.000129/weather?lang=zh_CN&device_id={}".format(ran)
res = requests.get(url).json()
msg = "XZZ为您播报近期天气\n-------------------------------------\n"
msg += "日期 | 温度 | 湿度 | 天气 |\n-------------------------------------"
result = res["result"]["daily"]
now = datetime.datetime.now()
weather_summary = {
"CLEAR_DAY": "",
"CLEAR_NIGHT": "",
"CLOUD_DAY_WIDGET": "多云转晴",
"CLOUDY": "",
"HAZE": "",
"HAZE_WIDGET": "",
"PARTLY_CLOUD_NIGHT": "多云转晴",
"PARTLY_CLOUD_NIGHT_WIDGET": "多云转晴",
"PARTLY_CLOUD_WIDGET": "",
"PARTLY_CLOUDY_DAY": "多云转晴",
"PARTLY_CLOUDY_NIGHT": "多云转晴",
"RAIN": "",
"RAIN_HEAVY": "大雨",
"RAIN_LIGHT": "小雨",
"RAIN_MIDDLE": "中雨",
"RAIN_NORMAL_WIDGET": "大雨",
"SNOW": "",
"SNOW_WIDGET": "",
"SUNSHINE_NIGHT_WIDGET": "",
"SUNSHINE_WIDGET": "",
"WIND": "",
}
for i in range(5):
msg += "\n"
msg += "{} | ".format((now + datetime.timedelta(days=i)).strftime("%Y-%m-%d"))
msg += "{} | ".format(format(result["temperature"][i]["avg"], ".2f"))
msg += "{} | ".format(format(result["humidity"][i]["avg"], ".2f"))
msg += "{} | ".format(weather_summary[result["skycon"][i]["value"]])
return msg
if __name__ == "__main__":
Ans().GETMSG()

68
worker/zhaoan.py Normal file
View file

@ -0,0 +1,68 @@
from zzcore import StdAns
import requests
import sxtwl
from datetime import datetime
from config import HFWEATHERKEY
class Ans(StdAns):
def GETMSG(self):
msg = f'早上好,今天是{calendar()}\n\n'
msg += getWeather() + '\n\n'
t = requests.get('https://v1.hitokoto.cn/?c=k&encode=text').text
msg += t
return msg
def getWeather(id='101120206'):
def wemoji(text):
if '' in text:
return text + '🌨'
if '' in text:
return text + '🌧️'
if '' in text:
return text + ''
if '' in text:
return text + '🌤'
if '' in text:
return text + '☀️'
return text
url = 'https://devapi.heweather.net/v7/weather/3d'
params = {
'location': id,
'key': HFWEATHERKEY,
}
r = requests.get(url=url, params=params).json()
tdw = r['daily'][0]
ndw = r['daily'][1]
weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])}{tdw['windDirNight']}{tdw['windScaleNight']}级。明日日间{wemoji(ndw['textDay'])},温度{ndw['tempMin']}{ndw['tempMax']}℃。"
if float(tdw['precip']) > 0:
weather += '\n记得收好衣服,出门带伞~'
return weather
def calendar():
ymc = ["十一", "十二", "", "", "", "", "", "", "", "", "", ""]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五",
"十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
zmc = ["", "", "", "", "", "", ""]
nowdate = datetime.now()
y = nowdate.year
m = nowdate.month
d = nowdate.day
zc = int(nowdate.strftime("%W")) - 34
z = zmc[nowdate.weekday()]
lunar = sxtwl.Lunar()
lunarday = lunar.getDayBySolar(y, m, d)
lunardaychinese = f"{ymc[lunarday.Lmc]}{rmc[lunarday.Ldi]}"
if lunarday.Lleap:
lunardaychinese = "" + lunardaychinese
cal = f"{m}{d}日,农历{lunardaychinese},本学期第{zc}周,星期{z}"
return cal