forked from inannan423/wx_weather_class_push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eve.py
76 lines (56 loc) · 1.82 KB
/
eve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import random
from datetime import date, datetime
import requests
from wechatpy import WeChatClient
from wechatpy.client.api import WeChatMessage
# 当前日期
today = datetime.now()
# 微信公众号 ID
app_id = os.environ["APP_ID"]
# 微信公众号 app_secret
app_secret = os.environ["APP_SECRET"]
# 高德天气接口密钥 key
key = os.environ["KEY"]
# 微信公众号 模板id
template_id = os.environ["TEMPLATE_ID_EVE"]
# 用户ID
user_id_1 = os.environ["USER_ID_1"]
user_id_2 = os.environ["USER_ID_2"]
# 以上环境变量不需要修改,只需要在 github 的 secrets 中添加即可
##################################
# 修改用户信息 #
##################################
user_id_list = [
{'user_id': user_id_1, "name": 'Orange', "date": "2021-04-02", "birthday": "05-28",
'city': '110108'}
# , {'user_id': user_id_2, "name": 'Orange', "date": "2021-04-02", "birthday": "05-28",
# 'city': '110108'}
]
##################################
# 以下为主代码,不需要修改 #
##################################
# 好听的情话 API
def get_words():
words = requests.get("https://api.shadiao.pro/chp")
if words.status_code != 200:
return get_words()
result = words.json()['data']['text']
print(result)
return result
# 随机文字颜色
def get_random_color():
return "#%06x" % random.randint(0, 0xFFFFFF)
# 发送消息 支持批量用户
def wx_push():
for user in user_id_list:
user_id = user.get('user_id')
print(user_id)
client = WeChatClient(app_id, app_secret)
wm = WeChatMessage(client)
data = {
"words": {"value": get_words(), "color": get_random_color()}
}
res = wm.send_template(user_id, template_id, data)
print(res)
wx_push()