-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathcheckIn_SpeedWeekendLottery.py
155 lines (135 loc) · 4.66 KB
/
checkIn_SpeedWeekendLottery.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
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
'''
new Env('周末大乐透')
cron: 0 0 * * 7
Author: BNDou
Date: 2024-08-04 16:35:13
LastEditTime: 2024-08-25 02:00:30
FilePath: \Auto_Check_In\checkIn_SpeedWeekendLottery.py
Description :
飞车PC端活动-周末大乐透
默认 每周日 0 点执行
配合 checkIn_SpeedWeekendLottery_getCK.py 使用
先运行 checkIn_SpeedWeekendLottery_getCK.py 复制返回值粘贴到环境变量 COOKIE_DALETOU 中即可
'''
import os
import re
import sys
import time
from urllib.parse import unquote
import requests
# 测试用环境变量
# os.environ['COOKIE_DALETOU'] = ''
try: # 异常捕捉
from utils.notify import send # 导入消息通知模块
except Exception as err: # 异常捕捉
print('%s\n❌加载通知服务失败~' % err)
def get_env():
'''
获取环境变量
:return: 环境变量
'''
# 判断 COOKIE_DALETOU 是否存在于环境变量
if "COOKIE_DALETOU" in os.environ:
# 读取系统变量以 \n 或 && 分割变量
cookie_list = re.split('\n|&&', os.environ.get('COOKIE_DALETOU'))
else:
# 标准日志输出
print('❌未添加 COOKIE_DALETOU 变量')
send('周末大乐透', '❌未添加 COOKIE_DALETOU 变量')
# 脚本退出
sys.exit(0)
return cookie_list
class WeekendLottery:
def __init__(self, cookie):
self.cookie = cookie
self.p_uin = re.search(r'p_uin=(\S+);', cookie).group(1)
self.sArea = re.search(r'sArea=(\S+);', cookie).group(1)
self.g_tk = self.getG_tk(re.search(r'skey=(\S+);', cookie).group(1))
def getG_tk(self, skey):
"""官方算法:根据skey计算g_tk"""
hash = 5381
for i in range(len(skey)):
hash += (hash << 5) + ord(skey[i])
return hash & 2147483647
def getRemainingLotteryCount(self):
'''
查询剩余抽奖次数
'''
url = f"https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=369402"
headers = {'Cookie': self.cookie}
data = {
"sArea": self.sArea,
"sServiceType": "speed",
"iActivityId": "369402",
"iFlowId": "750956",
"g_tk": self.g_tk
}
response = requests.post(url, headers=headers, data=data)
response.encoding = "utf-8"
response = response.json()
if response["flowRet"]["iRet"] == "0":
if int(response['modRet']['sOutValue1']) // 50 > 7:
count = 7 - int(response['modRet']['sOutValue2'])
else:
count = int(response['modRet']['sOutValue1']) // 50 - int(
response['modRet']['sOutValue2'])
return f"本周活跃度:{response['modRet']['sOutValue1']}\n剩余抽奖次数:{count}\n", count
else:
return response["flowRet"]["sMsg"] + "\n", None
def lottery(self):
'''
抽奖
'''
url = f"https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=369402"
headers = {'Cookie': self.cookie}
data = {
"sArea": self.sArea,
"sServiceType": "speed",
"iActivityId": "369402",
"iFlowId": "750765",
"g_tk": self.g_tk
}
response = requests.post(url, headers=headers, data=data)
response.encoding = "utf-8"
response = response.json()
if response["flowRet"]["iRet"] == "0":
return unquote(response["modRet"]["sMsg"]) + "\n"
else:
return unquote(response["flowRet"]["sMsg"]) + "\n"
def run(self):
'''
主函数
'''
msg = f"🚗账号 {self.p_uin} {'电信区' if self.sArea == '1' else '联通区' if self.sArea == '2' else '电信2区'}\n"
# 查询次数
log, count = self.getRemainingLotteryCount()
msg += log
# 抽奖
if count is not None and count > 0 and count < 8:
msg += "🎉开始抽奖\n"
count *= 2
while count > 0:
msg += self.lottery()
time.sleep(0.4)
count -= 1
return msg
def main():
msg = ""
threads = []
global cookie_daletou
cookie_daletou = get_env()
print("✅检测到共", len(cookie_daletou), "个飞车账号")
i = 0
while i < len(cookie_daletou):
# 执行任务
msg += WeekendLottery(cookie_daletou[i]).run()
i += 1
return msg
if __name__ == "__main__":
print("----------周末大乐透开始抽奖----------")
msg = main()
print("----------周末大乐透执行完毕----------")
try:
send('周末大乐透', msg)
except Exception as err:
print('%s\n❌错误,请查看运行日志!' % err)