-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
651 lines (607 loc) · 28.5 KB
/
main.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import time
import faker
import random
import asyncio
import traceback
from Db.DbClient import DbClient
from Util.Function import current_unix
from Config.ConfigGetter import config
from Util import EncryptParams, Printer, NetEaseLogin, Notification
fake = faker.Faker(locale='zh_CN')
class NetEaseLottery:
def __init__(self):
# 加密 日志 数据库
self.enc = EncryptParams()
self.log = Printer()
self.db = DbClient()
# 数据表
self.raw_event = 'raw_event'
self.used_event = 'used_event'
# pass
self.session = None
self.user_box = []
self.lottery_list = []
self.pre_scan_list = []
self.designation_list = []
self.lock = {
'scan': 0,
}
self.__init_user_manager()
# 初始化用户管理
def __init_user_manager(self):
if self.user_box and self.session:
return
temp = []
accounts = config.user_accounts
for account in accounts:
if account['user_id'] in temp:
continue
for key, value in account.items():
if not value or value == 'invalid':
break
else:
try:
account['session'] = self.login(
account['username'], account['password']
)
if account['type'] == 'default':
self.session = account['session']
self.user_box.append(account)
except Exception as e:
self.log.printer("LOGIN", e)
continue
temp.append(account['user_id'])
if not self.user_box:
exit("有效用户为0,请检查配置!")
if not self.session:
self.session = self.user_box[0]['session']
self.user_box[0]['type'] = 'default'
# 请求中心
def _requests(self, method, url, decode=2, retry=10, timeout=15, **kwargs):
if method in ["get", "post"]:
for _ in range(retry + 1):
try:
response = getattr(self.session, method)(
url, timeout=timeout, **kwargs
)
return response.json() if decode == 2 else response.content if decode == 1 else response
except Exception as e:
self.log.printer("REQUEST", "出现错误 {e}")
time.sleep(1)
return None
# 请求中心
def _multi_requests(self, session, method, url, decode=2, retry=10,
timeout=15,
**kwargs):
if method in ["get", "post"]:
for _ in range(retry + 1):
try:
response = getattr(session, method)(
url, timeout=timeout, **kwargs
)
return response.json() if decode == 2 else response.content if decode == 1 else response
except Exception as e:
self.log.printer("MULTI_REQUEST", "出现错误 {e}")
time.sleep(1)
return None
# 登陆
def login(self, username, password):
return NetEaseLogin().login(username=username, password=password)
# 用户相关
async def users(self):
while True:
try:
user_len = len(self.user_box)
for _ in range(user_len):
await asyncio.sleep(30)
user = self.user_box.pop(0)
survive_status = self.check_survive(user)
if not survive_status:
user = self.flush_session(user)
self.user_box.append(user)
self.log.printer("SURVIVE", "休眠12小时后继续")
await asyncio.sleep(12 * 60 * 60)
except Exception as e:
self.log.printer("SURVIVE", f"流程出错 {e},稍后重试")
self.user_box.append(user)
await asyncio.sleep(60)
# 转发回滚
async def client(self):
while True:
try:
self.forward()
self.rollback()
self.log.printer("CLIENT", "休眠1小时后继续")
await asyncio.sleep(60 * 60)
except Exception as e:
self.log.printer("CLIENT", f"流程出错 {e},稍后重试")
await asyncio.sleep(60)
# 迷你扫描
async def mini_scan(self):
while True:
try:
await asyncio.sleep(3 * 60)
self.scan_lottery_id()
self.repeat_lottery()
self.log.printer("SERVER_MASTER", "休眠14小时后继续")
await asyncio.sleep(14 * 60 * 60)
except Exception as e:
self.log.printer("SERVER_MASTER", f"流程出错 {e},稍后重试")
await asyncio.sleep(60)
# 完整扫描
async def full_scan(self):
while True:
try:
await asyncio.sleep(10 * 60)
self.designation_section()
self.repeat_lottery_scan()
self.log.printer("SERVER_SLAVE", "休眠4小时后继续")
await asyncio.sleep(4 * 60 * 60)
except Exception as e:
self.log.printer("SERVER_SLAVE", f"流程出错 {e},稍后重试")
await asyncio.sleep(60)
# 字符匹配抽奖id
def match_lottery_id(self, json_data):
pattern = r'\"lotteryId\":(\d+),\"status\":(\d)'
str_data = str(json_data) \
.replace(" ", "") \
.replace("\n", "") \
.replace("\r", "")
return re.findall(pattern, str_data)
# 去重
def repeat_lottery(self):
self.db.change_table(self.raw_event)
temp_lottery_list = self.db.query_key('lottery_id')
self.log.printer("M_SCAN", f"当前共有 {len(self.lottery_list)} 个动态抽奖需要去重")
for lottery_id in self.lottery_list:
time.sleep(2)
if lottery_id in temp_lottery_list:
continue
data = self.fetch_lottery_info(lottery_id)
# if data['status'] == 2:
# continue
self.db.change_table(self.raw_event)
self.db.insert_raw(
data['uid'], data['event_msg'], data['event_id'],
data['lottery_id'], data['lottery_time']
)
self.lottery_list = []
self.log.printer("M_SCAN", f"动态抽奖库存去重完成")
# 扫描动态
def scan_lottery_id(self):
url = 'http://music.163.com/weapi/act/event?csrf_token='
scan_page = 10
max_page = '100'
last_time = '-1'
act_ids = {
'互动抽奖': '44196506',
'抽奖活动': '17731067',
'转发抽奖': '20397151',
'抽奖福利': '19873053',
'粉丝福利': '3753053'
}
for act_id in act_ids.keys():
for page in range(0, scan_page):
self.log.printer("M_SCAN", f'开始扫描 {act_id} 第 {page + 1} 页')
while True:
try:
params = {
"actid": act_ids[act_id],
"total": "true",
"limit": "20",
"lasttime": last_time,
"pagesize": max_page,
"getcounts": "true",
"csrf_token": ""
}
params = self.enc.get(params)
response = self.session.post(url, params=params).json()
# 匹配 未过滤
match_data_all = self.match_lottery_id(response)
for match_data in match_data_all:
try:
lottery_id = int(match_data[0])
lottery_status = int(match_data[1])
except Exception as e:
continue
status = 'valid' if lottery_status == 1 else 'invalid'
self.log.printer(
"M_SCAN",
f"title: {act_id}, lotteryId: {lottery_id}, status: {status}"
)
if lottery_id in self.lottery_list:
# or lottery_status == 2:
continue
self.lottery_list.append(lottery_id)
last_time = response['lasttime']
break
except Exception as e:
traceback.print_exc()
self.log.printer("M_SCAN", f"扫描动态出现错误 {e}, 稍后重试!")
if not response['more']:
break
self.log.printer("M_SCAN",
f"此次扫描已结束,当前库存 {len(self.lottery_list)} 个未验证动态抽奖")
# 分配扫描段
def designation_section(self):
if len(self.pre_scan_list) == 0:
self.db.change_table(self.raw_event)
lottery_data = self.db.query_valid()
valid_lottery_list = []
for lottery in lottery_data:
valid_lottery_list.append(lottery['lottery_id'])
self.calc_section(valid_lottery_list)
for _ in range(1000):
if len(self.pre_scan_list) == 0:
break
self.designation_list.append(self.pre_scan_list.pop(0))
self.log.printer(
"F_SCAN",
f"预备扫描 {len(self.pre_scan_list)} 分配扫描 {len(self.designation_list)}"
)
# 去重扫描
def repeat_lottery_scan(self):
self.db.change_table(self.raw_event)
exist_lottery_list = self.db.query_key('lottery_id')
self.log.printer("F_SCAN",
f"当前分配 {len(self.designation_list)} 个动态抽奖需要扫描")
for lottery_id in self.designation_list:
time.sleep(random.uniform(1.5, 2))
if lottery_id in exist_lottery_list:
continue
data = self.fetch_lottery_info(lottery_id)
if data is None:
continue
self.db.change_table(self.raw_event)
self.db.insert_raw(
data['uid'], data['event_msg'], data['event_id'],
data['lottery_id'], data['lottery_time']
)
self.designation_list = []
self.log.printer("F_SCAN", f"动态抽奖去重扫描完成")
# 生存检测
def check_survive(self, user):
url = f"http://music.163.com/api/lottery/event/get?lotteryId=1"
try:
response = user['session'].get(url).json()
# {"code":301,"message":"系统错误","debugInfo":null}
if response['code'] == 301:
self.log.printer("SURVIVE", f"{user['username']} 存活检测 -> fail")
return False
self.log.printer("SURVIVE", f"{user['username']} 存活检测 -> success")
return True
except Exception as e:
self.log.printer("SURVIVE", f"{user['username']} 存活检测 -> {e}")
return None
# 刷新session
def flush_session(self, user):
try:
user['session'] = self.login(
user['username'], user['password']
)
if user['type'] == 'default':
self.session = user['session']
self.log.printer(
"SURVIVE",
f"{user['username']} 刷新SESSION -> success"
)
except Exception as e:
self.log.printer("SURVIVE", f"{user['username']} 刷新SESSION -> {e}")
return user
# 取动态抽奖信息
def fetch_lottery_info(self, lottery_id):
url = f"http://music.163.com/api/lottery/event/get?lotteryId={lottery_id}"
try:
response = self.session.get(url).json()
if response['code'] == 200:
data = {
'uid': response['data']['user']['userId'],
'event_msg': response['data']['event']['eventMsg'],
'event_id': response['data']['lottery']['eventId'],
'lottery_id': response['data']['lottery']['lotteryId'],
'lottery_time': response['data']['lottery'][
'lotteryTime'],
'prizes': response['data']['prize'],
'status': response['data']['lottery']['status']
}
self.log.printer("LOTTERY_INFO", f"{lottery_id} -> 命中抽奖")
return data
elif response['code'] == 404:
self.log.printer(
"LOTTERY_INFO",
f"{lottery_id} -> {response['message']}"
)
else:
self.log.printer("LOTTERY_INFO",
f"{lottery_id} -> {response}")
return None
except Exception as e:
self.log.printer("LOTTERY_INFO", f"{lottery_id} -> {e}")
# {"code":404,"message":"动态资源不存在","debugInfo":null}
return None
# 计算区间
def calc_section(self, lottery_id_list):
scan_list = []
for lottery_id in lottery_id_list:
if int(lottery_id) < 10000:
start = 1
end = 9999
else:
start = int(f"{str(lottery_id)[:-4]}0000")
end = int(f"{str(lottery_id)[:-4]}9999")
scan_list.append([start, end])
for scan in scan_list:
if scan_list.count(scan) == 1:
continue
# 第一方案
self.pre_scan_list += list(range(scan[0], scan[1]))
self.pre_scan_list = list(set(self.pre_scan_list))
# 第二方案
# self.pre_scan_list = list(set(self.pre_scan_list).union(set(list(range(start, end)))))
# self.log.printer(f"当前区间 {start},{end} 已有数据 {len(self.pre_scan_list)}")
# 转发
def publish(self, user, raw_event_id, event_id, event_uid, msg):
try:
csrf = self.get_csrf(user)
url = f"http://music.163.com/weapi/event/forward?csrf_token={csrf}"
params = {
"forwards": msg,
"id": event_id,
"eventUserId": event_uid,
"checkToken": "",
"csrf_token": csrf
}
params = self.enc.get(params)
response = user['session'].post(url, params=params).json()
self.log.printer("FORWARD", response)
self.db.change_table(self.used_event)
self.db.insert_used(
user['username'], response['data']['eventId'], raw_event_id
)
url = f'http://music.163.com/weapi/feedback/weblog?csrf_token={csrf}'
params = {
"logs": '[{"action": "eventclick","json":{"id": %s,"sourceid": %s,"alg": "","contentType": "user_event","actionType": "forward"}}]' % (
event_id, event_uid),
"csrf_token": csrf
}
params = self.enc.get(params)
response = user['session'].post(url, params=params).json()
self.log.printer("FORWARD", response)
except Exception as e:
self.log.printer("FORWARD", f"{response} -> {e}")
return False
return True
# 获取csrf
def get_csrf(self, user):
return (user['session'].cookies.get_dict())['__csrf']
# 关注
def follow(self, user, follow_uid):
csrf = self.get_csrf(user)
url = f"http://music.163.com/weapi/user/follow/{follow_uid}?csrf_token={csrf}"
user['session'].headers.update(
{
'Host': 'music.163.com',
'Origin': 'http://music.163.com',
'Referer': f"http://music.163.com/user/home?id={follow_uid}",
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
}
)
params = {
"followId": follow_uid,
"checkToken": "",
"csrf_token": csrf
}
params = self.enc.get(params)
response = user['session'].post(url, params=params)
self.log.printer("FOLLOW", response.json())
# 取消关注
def un_follow(self, user, follow_uid):
csrf = self.get_csrf(user)
url = f'http://music.163.com/weapi/user/delfollow/{follow_uid}?csrf_token={csrf}'
params = {
"followId": follow_uid,
"csrf_token": csrf
}
params = self.enc.get(params)
response = user['session'].post(url, params=params).json()
self.log.printer("UN_FOLLOW", response)
# 过滤关键词 钓鱼测试
def filter_keywords(self, desp):
keys = [
'禁言', '测试', 'vcf', '体验中奖', '中奖的感觉', '赶脚', '感脚', '感jio',
'黑名单', '拉黑', '拉黑', '脸皮厚', '没有奖品', '无奖', '脸皮厚', 'ceshi',
'测试', '脚本', '抽奖号', '不要脸', '至尊vip会员7天', '高级会员7天', '万兴神剪手',
'测试', '加密', 'test', 'TEST', '钓鱼', '炸鱼', '调试'
]
for key in keys:
if key in desp:
return False
return True
# 过滤关键词 奖品
def filter_prizes(self, prizes):
keys = [
'编曲', '作词', '半价', '打折', '机器', '禁言', '测试', 'vcf', '体验中奖',
'中奖的感觉', '录歌', '混音', '一毛', '0.1元', '1角', '0.5元', '5毛',
'赶脚', '感脚', '曲风', '专辑封面', '封面', '一元红包', '感jio', '名片赞',
'黑名单', '拉黑', '拉黑', '脸皮厚', '没有奖品', '无奖', '脸皮厚',
'测试', '脚本', '抽奖号', '不要脸', '至尊vip会员7天', '高级会员7天',
'测试', '加密', 'test', 'TEST', '钓鱼', '炸鱼', '调试', '歌曲定制',
'学习视频', '修图视频', '作词', '免费编曲', '后期制作', '编曲搬家',
'内容自定', '音乐人一个', '私人唱歌', '感恩', '作业', '八字', '算命',
'电台', '情感视频', '万兴神剪手', '学习修图', '写一首歌', 'ceshi',
'管饱', 'dong tai ga', '电话唱歌', '感谢转发', '非独家使用权', '前排沙发',
'琴谱', '有就送', '什么也不给', '什么都没有', '租赁', '伴奏', '定制beat',
'定制logo', '惊喜软件', '终于中奖', '加群', '第一批粉丝', '祝大家',
'内部群', '老粉', '仅关注', '仅我关注', '打字粉丝ID', '手打粉丝ID',
'人声采集', '采样包', '约稿', 'remix', '明信片', '感受中奖', '快落',
'中奖的快乐', '单曲', '主题创作', '猎妈', '签名照', '数字专辑', '除夕夜',
'专辑', '励志的话', '亲笔签名', 'up', '扫码进群', '粉丝群', '签名写真',
'纹身', '祝你', '红包雨', '电子书', '我', '专辑', '好友位', '豪车优惠',
'观众老爷', '的支持', '拉黑', '黑名单', '脸皮厚', '没有奖品', '无奖',
'测试', '测试', '测试', '脚本', '抽奖号', '星段位', '星段位', '圣晶石',
'水晶', '水晶', '万兴神剪手', '万兴神剪手', 'ceshi', 'QQ', '测试',
'自付邮费', '自付邮费', 'test', 'Test', 'TEST', '加密', '测试用',
'VX', 'vx', 'ce', 'shi', '这是一个', 'lalall', '第一波', '第二波',
'策是', '我是抽奖', '照片', '穷', '0.5', '一角', '冥币', '加速器',
'硬币', '无奖品', '白名单', '圣晶石', '奖品B', '奖品C', '五毛', '第三波',
'0.1', '五毛二', '一分', '一毛', '0.52', '0.66', '0.01', '0.77', '0.16',
'0.88', '双排', '1毛', '1分', '1角', 'P口罩', '素颜', '写真', '图包',
'自拍', '日历', '0.22', '房间抽奖', 'CESHI', '脸皮厚', 'ceshi', '奖品A',
'抽奖标题', '測試', '越南盾', '啥都没有', '哈哈哈', '作曲', '一首', '手绘',
'学霸', 'buff', '头像', '剩的', '中奖的', 'Ziyoda', 'Hilola', 'beden', '新专',
'采样', '音频', '海报', '关注', '粉丝ID', '电子书', '我', '半价', '优惠券',
'微博', '互粉', '真心话', '回答', '签名海报', '不想要', '抱抱', '拥抱', 'WAV',
'伴奏', '邀请函', '你猜猜', '什么也没有', '什么都', '什么也', '这不是抽奖',
'真欧', '很欧', '使用权', '曲谱', '啥也没有', '木有', '哈哈哈', '车载音乐',
'中奖的', '中奖滴', '会员歌曲', '一首歌', '必唱', '发文件', '词作', '购买资格',
'粉群', '优惠', '折扣', 'hoholive', 'surat', 'hisyat', '免费观', '免费演',
'免费门', '谢谢参与', 'vx call u', '新婚快乐', '歌曲使用权', '普通mp3使用权',
'破解版', '土嗨', '给你写', '普通mp3', '啥也不是', '歌曲大礼包', '歌手大礼包',
'无损wav', 'mp3使用权', 'wav使用权', '曲谱', '阿里嘎多', '代金券', '你的想法',
'封面制作', '一句喵喵喵', '互关', '逢考必过', '云豆', '擁抱', '音色包', '点赞',
'动态', '冠军照', '手抄', '邮费自理', '*7天', '7天', '周卡', '七日', '七天',
'钥匙扣', '中奖辣', '7日', '给我转账', '体验卡', '吻', '么么', '没有', '分享图片',
'黑胶会员7天', '黑胶会员5天', '评论区', '热评', '微信', 'vx', '原创', '参与',
'文档', '谢谢', '感谢', '祝福', '沾沾福', '一周', '歌曲', '评论', '赞赏', ',',
'签名', '文件', '英语四级', '新年快乐',
]
# 过滤 一等奖 奖品
for prize in prizes:
for key in keys:
if key in prize['name']:
return False
break
return True
# 过滤404动态
def filter_dynamic(self, event_id):
pass
# 概率性抽奖
def filter_probability(self):
pass
# 过滤转发数据
def filter_repost(self, lottery_id):
data = self.fetch_lottery_info(lottery_id)
# 抽奖存在异常
if data is None:
return False, '获取动态抽奖信息异常'
# 抽奖存在异常关键字返回假
if not self.filter_keywords(data['event_msg']):
return False, '标题内容存在异常关键字'
# 抽奖奖品存在异常
if not self.filter_prizes(data['prizes']):
return False, '奖品内容存在异常关键字'
return True, None
# 转发动态
def forward(self):
messages = [
'转发动态', '转发动态', '', '好运来', '啊~', '哈哈哈', '抽奖奖(⌒▽⌒)',
'中奖绝缘体', '绝缘体', '求脱非入欧', '好运', '中奖绝缘体表示想中!',
'呜呜呜非洲人来了', '选我吧', '一定会中', '好运bufff', '滴滴滴', '哇哇哇哇',
'拉低中奖率', '万一呢', '非酋日常', '加油', '抽中吧', '我要', '想欧一次!',
'拉低中奖率233', '想要...', '路过拉低中奖率', '希望有个好运气',
'中奖', '什么时候才会抽到我呢?', '试试水,看看能不能中', '过来水一手',
'这辈子都不可能中奖的', '先拉低中奖率23333', '先抽奖,抽不到再说',
'嘤嘤嘤', '捞一把', '我就想中一次', '拉低拉低', '试一试', '搞一搞',
'中奖什么的不可能的( ̄▽ ̄)', '听说我中奖了?', '脱非转欧', 'emm',
]
self.db.change_table(self.raw_event)
data = self.db.query_forward()
for d in data:
event_status, status_msg = self.filter_repost(d['lottery_id'])
if not event_status:
self.log.printer(
"REPOST", f"当前动态 {d['lottery_id']} {status_msg} 跳过"
)
continue
for user in self.user_box:
message = random.choice(messages)
status = self.publish(user, d['id'], d['event_id'], d['uid'],
message)
if status:
self.follow(user, d['uid'])
self.db.change_table(self.raw_event)
self.db.update_raw_reposted(d['lottery_id'])
# 删除动态
def del_event(self, user, event_id):
csrf = self.get_csrf(user)
url = f'http://music.163.com/weapi/event/delete?csrf_token={csrf}'
params = {
"type": "delete",
"id": event_id,
"transcoding": "false",
"csrf_token": csrf
}
params = self.enc.get(params)
response = user['session'].post(url, params=params).json()
self.log.printer("DEL_EVENT", response)
# 回滚
def rollback(self):
self.db.change_table(self.raw_event)
data = self.db.query_delete()
for d in data:
event_status, status_msg = self.filter_repost(d['lottery_id'])
for user in self.user_box:
if not event_status:
self.log.printer(
"ROLLBACK", f"当前动态 {d['lottery_id']} {status_msg} 跳过"
)
self.db.change_table(self.used_event)
pre_d = self.db.query_pre_event(user['username'], d['id'])
if pre_d is not None:
self.del_event(user, pre_d['pre_event_id'])
# 如果没查询到 取消关注 TODO 错误回滚
self.un_follow(user, d['uid'])
continue
if not self.win_check(user, d['lottery_id']):
if (d['lottery_time'] + 5 * 60 * 60) > current_unix():
continue
self.db.change_table(self.used_event)
pre_d = self.db.query_pre_event(user['username'], d['id'])
if pre_d is not None:
self.del_event(user, pre_d['pre_event_id'])
# 如果没查询到 取消关注 TODO 错误回滚
self.un_follow(user, d['uid'])
self.db.change_table(self.raw_event)
self.db.update_raw_deleted(d['lottery_id'])
# 中奖检测
def win_check(self, user, lottery_id):
url = f"http://music.163.com/api/lottery/event/get?lotteryId={lottery_id}"
response = self.session.get(url).json()
prize_ids = response['data']['lottery']['prizeId']
prize_ids = prize_ids.strip('[').strip(']').split(',')
try:
for prize_id in prize_ids:
data = response['data']['luckUsers'][prize_id]
for d in data:
if d['userId'] == int(user['user_id']):
prizes = response['data']['prize']
for index, prize in enumerate(prizes):
if str(prize['id']) == prize_id:
prize_level = index + 1
prize_name = prize['name']
info = f"""亲爱的 [{user['username']} -> {user['user_id']}] 您好:
恭喜您在【{response['data']['user']['nickname']}】发布的动态互动抽奖活动中,喜获奖品啦!
>>> 互动抽奖{lottery_id} -> {prize_level}等奖 -> {prize_name}] <<<
请前往网易云音乐APP查看详情,尽快填写中奖信息或领取奖品。"""
self.log.printer("WIN", info)
# (https://music.163.com/st/m#/lottery/detail?id={lottery_id})
# 中奖提醒
Notification().notice_handler('网易云互动抽奖', info)
return True
except Exception as e:
return False
return False
if __name__ == '__main__':
net_ease = NetEaseLottery()
tasks = [
net_ease.client(),
net_ease.users(),
net_ease.mini_scan(),
net_ease.full_scan()
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
loop.close()