mirror of
https://github.com/Sitoi/dailycheckin.git
synced 2024-11-17 13:48:03 +08:00
添加每日天气 & 每日一句
This commit is contained in:
parent
51e18ce69a
commit
6bee110a94
@ -11,11 +11,12 @@
|
||||
- [x] 吾爱破解每日签到: 每日签到获取2枚吾爱币
|
||||
- [x] 有道云笔记每日签到: 每日签到获取存储空间
|
||||
- [x] 网易云音乐每日签到升级: 每日自动登录签到 + 刷歌 310 首
|
||||
- [x] 每日天气预报: 可以获取指定的多个城市天气信息
|
||||
- [x] 每日一句: 从词霸中获取每日一句,带英文
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] 添加其他通知服务
|
||||
- [ ] 修改通知结构
|
||||
- [ ] 添加 GitHub Actions 使用
|
||||
- [ ] 添加新的签到脚本,请到 [ISSUE](https://github.com/Sitoi/DailyCheckIn/issues) 中提交
|
||||
|
||||
@ -120,4 +121,5 @@ TODO
|
||||
|music163.`music163_password`|网易云音乐|非必须|[网易云音乐](https://music.163.com/) 帐号的密码|
|
||||
|baidu_url_submit.`data_url`|百度搜索资源平台|非必须|提交网站的 URL 链接,参考:[baidu_urls.txt](https://cdn.jsdelivr.net/gh/Sitoi/Sitoi.github.io/baidu_urls.txt)|
|
||||
|baidu_url_submit.`submit_url`|百度搜索资源平台|非必须|[百度搜索资源平台](https://ziyuan.baidu.com/site/index#/) 提交百度网站的目标 URL,参考格式:`http://data.zz.baidu.com/urls?site=https://sitoi.cn&token=xxxxx`|
|
||||
|baidu_url_submit.`times`|百度搜索资源平台|非必须|每日对同一个网站提交次数|
|
||||
|`weather`|每日天气|非必须|填写城市名称,点击查看[城市名称列表](./weather/city.json)|
|
||||
|`motto`|每日一句|非必须|是否开启默认为 false|
|
@ -3,6 +3,10 @@
|
||||
"dingtalk_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"dingtalk_access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
},
|
||||
"weather": [
|
||||
"上海"
|
||||
],
|
||||
"motto": true,
|
||||
"iqiyi": [
|
||||
{
|
||||
"iqiyi_cookie": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
22
index.py
22
index.py
@ -5,15 +5,18 @@ import hmac
|
||||
import json
|
||||
import time
|
||||
import urllib.parse
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
from baidu_url_submit import BaiduUrlSubmit
|
||||
from iqiyi import IQIYICheckIn
|
||||
from kgqq import KGQQCheckIn
|
||||
from motto.motto import Motto
|
||||
from music163 import Music163CheckIn
|
||||
from pojie import PojieCheckIn
|
||||
from vqq import VQQCheckIn
|
||||
from weather import Weather
|
||||
from youdao import YouDaoCheckIn
|
||||
|
||||
|
||||
@ -41,7 +44,7 @@ def main_handler(event, context):
|
||||
data = json.loads(f.read())
|
||||
dingtalk_secret = data.get("dingtalk", {}).get("dingtalk_secret")
|
||||
dingtalk_access_token = data.get("dingtalk", {}).get("dingtalk_access_token")
|
||||
content_list = []
|
||||
content_list = [f'当前时间: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}']
|
||||
iqiyi_cookie_list = data.get("iqiyi", [])
|
||||
if iqiyi_cookie_list:
|
||||
msg_list = IQIYICheckIn(iqiyi_cookie_list=iqiyi_cookie_list).main()
|
||||
@ -74,13 +77,24 @@ def main_handler(event, context):
|
||||
|
||||
music163_account_list = data.get("music163", [])
|
||||
if music163_account_list:
|
||||
msg_list = Music163CheckIn(music163_account_list=music163_account_list, ).main()
|
||||
msg_list = Music163CheckIn(music163_account_list=music163_account_list).main()
|
||||
content_list += msg_list
|
||||
|
||||
use_time_info = f"\n\n本次任务使用时间: {time.time() - start_time} 秒"
|
||||
city_name_list = data.get("weather", [])
|
||||
if city_name_list:
|
||||
msg_list = Weather(city_name_list=city_name_list).main()
|
||||
content_list += msg_list
|
||||
|
||||
motto = data.get("motto")
|
||||
if motto:
|
||||
msg_list = Motto().main()
|
||||
content_list += msg_list
|
||||
|
||||
use_time_info = f"本次任务使用时间: {time.time() - start_time} 秒"
|
||||
content_list.append(use_time_info)
|
||||
content = "\n-----------------------------\n".join(content_list)
|
||||
content = "\n-----------------------------\n\n".join(content_list)
|
||||
print(content)
|
||||
|
||||
if dingtalk_access_token and dingtalk_secret:
|
||||
message_to_dingtalk(
|
||||
dingtalk_secret=dingtalk_secret,
|
||||
|
1
motto/__init__.py
Normal file
1
motto/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
32
motto/motto.py
Normal file
32
motto/motto.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class Motto:
|
||||
@staticmethod
|
||||
def main():
|
||||
"""
|
||||
从词霸中获取每日一句,带英文。
|
||||
:return:
|
||||
"""
|
||||
resp = requests.get(url="http://open.iciba.com/dsapi")
|
||||
if resp.status_code == 200:
|
||||
content_json = resp.json()
|
||||
content = content_json.get("content")
|
||||
note = content_json.get("note")
|
||||
msg = [f"{content}\n{note}\n"]
|
||||
else:
|
||||
msg = []
|
||||
print(msg)
|
||||
return msg
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"), "r", encoding="utf-8") as f:
|
||||
data = json.loads(f.read())
|
||||
motto = data.get("motto")
|
||||
if motto:
|
||||
Motto().main()
|
2
weather/__init__.py
Normal file
2
weather/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from weather.weather import Weather
|
2559
weather/city.json
Normal file
2559
weather/city.json
Normal file
File diff suppressed because it is too large
Load Diff
45
weather/weather.py
Normal file
45
weather/weather.py
Normal file
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class Weather:
|
||||
def __init__(self, city_name_list):
|
||||
self.city_name_list = city_name_list
|
||||
|
||||
def main(self):
|
||||
"""
|
||||
获取天气信息。网址:https://www.sojson.com/blog/305.html
|
||||
:return:
|
||||
"""
|
||||
msg_list = []
|
||||
with open(os.path.join(os.path.dirname(__file__), "city.json"), "r", encoding="utf-8") as city_file:
|
||||
city_map = json.loads(city_file.read())
|
||||
for city_name in self.city_name_list:
|
||||
city_code = city_map.get(city_name, "101020100")
|
||||
weather_url = f"http://t.weather.itboy.net/api/weather/city/{city_code}"
|
||||
resp = requests.get(url=weather_url)
|
||||
if resp.status_code == 200 and resp.json().get("status") == 200:
|
||||
weather_json = resp.json()
|
||||
today_weather = weather_json.get("data").get("forecast")[1]
|
||||
today_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
notice = today_weather.get("notice")
|
||||
high = today_weather.get("high")
|
||||
low = today_weather.get("low")
|
||||
temperature = f"温度: {low[low.find(' ') + 1:]}/{high[high.find(' ') + 1:]}"
|
||||
wind = f"{today_weather.get('fx')}: {today_weather.get('fl')}"
|
||||
aqi = f"空气: {today_weather.get('aqi')}"
|
||||
msg = f"【{city_name}天气--{today_time}】\n{notice}。\n{temperature}\n{wind}\n{aqi}\n"
|
||||
print(msg)
|
||||
msg_list.append(msg)
|
||||
return msg_list
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"), "r", encoding="utf-8") as f:
|
||||
data = json.loads(f.read())
|
||||
_city_name_list = data.get("weather")
|
||||
Weather(city_name_list=_city_name_list).main()
|
Loading…
Reference in New Issue
Block a user