-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy path500w.py
More file actions
176 lines (148 loc) · 6.38 KB
/
500w.py
File metadata and controls
176 lines (148 loc) · 6.38 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
"""
双色球守号检测 + 冷号机选 + 企业微信&PushPlus 双推送(已加开奖日期)
"""
import requests
import random
import logging
from datetime import datetime
from collections import Counter
# ====================== 配置区 ======================
CONFIG = {
"weixin": {
"corpid": "", # 企业ID
"corpsecret": "", # 应用Secret
"touser": "@all", # @all 或具体成员
"agentid": "" # 应用ID(字符串)
},
"pushplus": {
"token": "你的PushPlus token" # 必填
}
}
# 你守的2注
FIXED_TICKETS = [
{"red": [2, 15, 20, 21, 24, 26], "blue": 1},
{"red": [3, 4, 11, 17, 23, 30], "blue": 6}
]
NUM_GENERATED = 2
HISTORY_LIMIT = 100
API_URL = "https://ms.zhcw.com/proxy/lottery-chart-center/history/SSQ"
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# ====================== 推送函数 ======================
def push_notification(contents: str):
try:
logger.info("开始发送推送通知")
# 企业微信
if all(CONFIG['weixin'].values()):
token_resp = requests.get(
f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
f"corpid={CONFIG['weixin']['corpid']}&corpsecret={CONFIG['weixin']['corpsecret']}",
timeout=10
).json()
if token_resp.get('errcode') == 0:
token = token_resp['access_token']
payload = {
"touser": CONFIG['weixin']['touser'],
"msgtype": "text",
"agentid": CONFIG['weixin']['agentid'],
"text": {"content": "双色球开奖通知\n" + contents}
}
resp = requests.post(
f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}",
json=payload, timeout=10
).json()
logger.info("企业微信推送成功" if resp['errmsg'] == 'ok' else f"企业微信失败: {resp}")
# PushPlus
if CONFIG['pushplus']['token']:
payload = {
"token": CONFIG['pushplus']['token'],
"title": "双色球开奖通知",
"content": contents.replace('\n', '<br>'),
"template": "html"
}
resp = requests.post("http://www.pushplus.plus/send", json=payload, timeout=10).json()
logger.info("PushPlus推送成功" if resp['code'] == 200 else f"PushPlus失败: {resp}")
logger.info("所有推送完成")
except Exception as e:
logger.error(f"推送异常: {e}")
# ====================== 数据获取 ======================
def get_latest_and_history():
headers = {"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
payload = {"limit": HISTORY_LIMIT, "page": 1, "params": {}}
try:
resp = requests.post(API_URL, headers=headers, json=payload, timeout=15)
resp.raise_for_status()
datas = resp.json()["datas"]
latest = datas[0]
red_str = latest["winningFrontNum"]
blue_str = latest["winningBackNum"]
period = latest.get("issue", "未知")
date = latest.get("openDate", "")[:10] # 开奖日期
latest_red = sorted(int(x) for x in red_str.split())
latest_blue = int(blue_str)
red_hist = [entry["winningFrontNum"].split() for entry in datas]
blue_hist = [int(entry["winningBackNum"]) for entry in datas]
return {
"period": period,
"date": date,
"red": latest_red,
"blue": latest_blue
}, red_hist, blue_hist
except Exception as e:
logger.error(f"获取开奖数据失败: {e}")
return None, None, None
# ====================== 中奖判断 & 冷号机选 ======================
def check_prize(tr, tb, wr, wb):
rh = len(set(tr) & set(wr))
bh = 1 if tb == wb else 0
if rh == 6 and bh: return "★★★★★ 一等奖 5亿到手!!! ★★★★★"
if rh == 6: return "二等奖!已经起飞!"
if rh == 5 and bh: return "三等奖!赚大了!"
if rh == 5 or (rh == 4 and bh): return "四等奖"
if rh == 4 or (rh == 3 and bh): return "五等奖"
if bh: return "六等奖(蓝球中)"
return "未中奖,继续守号~"
def generate_cold(red_hist, blue_hist):
red_all = [int(n) for sub in red_hist for n in sub]
red_c = Counter(red_all)
blue_c = Counter(blue_hist)
cold_red = [n for n, _ in sorted(red_c.items(), key=lambda x: x[1])[:18]]
cold_blue = [n for n, _ in sorted(blue_c.items(), key=lambda x: x[1])[:10]]
reds = sorted(random.sample(cold_red if len(cold_red) >= 6 else list(range(1,34)), 6))
blue = random.choice(cold_blue if cold_blue else list(range(1,17)))
return reds, blue
# ====================== 主程序 ======================
def main():
print(f"\n{'='*30} 双色球监测+机选 {datetime.now().strftime('%Y-%m-%d %H:%M')} {'='*30}")
result, r_hist, b_hist = get_latest_and_history()
if not result:
push_notification("【双色球】获取最新开奖数据失败,请检查网络或接口")
return
# 这里把开奖日期加进去了
lines = [
f"双色球 {result['period']} 已开奖!",
f"开奖日期:{result['date']}", # ← 新增这一行
f"开奖号码:{' '.join(f'{x:02d}' for x in result['red'])} + {result['blue']:02d}",
""
]
# 守号检测
for i, t in enumerate(FIXED_TICKETS, 1):
prize = check_prize(t["red"], t["blue"], result["red"], result["blue"])
rs = ' '.join(f'{x:02d}' for x in sorted(t["red"]))
print(f"守号第{i}注:{rs} + {t['blue']:02d} → {prize}")
lines.append(f"守号第{i}注:{rs} + {t['blue']:02d}")
lines.append(f" → {prize}")
lines.append("")
# 冷号机选
lines.append("今日冷号机选推荐:")
for i in range(NUM_GENERATED):
r, b = generate_cold(r_hist, b_hist)
rs = ' '.join(f'{x:02d}' for x in r)
print(f"机选第{i+1}注:{rs} + {b:02d}")
lines.append(f"{rs} + {b:02d}")
push_notification("\n".join(lines))
print("\n推送已发送(含开奖日期),祝好运连连!")
if __name__ == "__main__":
main()