forked from daidaojianke/jd_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd_polite.py
141 lines (122 loc) · 4.33 KB
/
jd_polite.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
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# @Time : 2021/8/27 1:37 下午
# @File : jd_polite.py
# @Project : jd_scripts
# @Cron : 9 16 * * *
# @Desc : 小鸽有礼
import asyncio
import json
import aiohttp
from utils.jd_init import jd_init
from utils.console import println
from config import USER_AGENT
from utils.process import process_start
@jd_init
class JdPolite:
"""
小鸽有礼
"""
headers = {
'origin': 'https://jingcai-h5.jd.com',
'user-agent': 'jdapp;' + USER_AGENT,
'lop-dn': 'jingcai.jd.com',
'accept': 'application/json, text/plain, */*',
'appparams': '{"appid":158,"ticket_type":"m"}',
'content-type': 'application/json',
'referer': 'https://jingcai-h5.jd.com/index.html'
}
activityCode = "1410048365793640448"
async def request(self, session, path, body=None, method='POST'):
"""
请求服务器数据
:return:
"""
try:
if not body:
body = {}
url = 'https://lop-proxy.jd.com/' + path
if method == 'POST':
response = await session.post(url, json=body)
else:
response = await session.get(url, json=body)
text = await response.text()
data = json.loads(text)
return data
except Exception as e:
println('{}, 请求服务器数据失败, {}'.format(self.account, e.args))
return {
'success': False
}
async def do_tasks(self, session, times=3):
"""
做任务
:return:
"""
if times < 0:
return
flag = False
res = await self.request(session, '/WonderfulLuckDrawApi/queryMissionList', [{
"userNo": "$cooMrdGatewayUid$",
"activityCode": self.activityCode
}])
if not res.get('success'):
println('{}, 获取任务列表失败!'.format(self.account))
return
task_list = res['content']['missionList']
for task in task_list:
if task['status'] == 10:
println('{}, 今日完成任务:{}!'.format(self.account, task['title']))
continue
flag = True
if task['status'] == 11:
for no in task['getRewardNos']:
body = [{
"activityCode": self.activityCode,
"userNo": "$cooMrdGatewayUid$",
"getCode": no
}]
res = await self.request(session, '/WonderfulLuckDrawApi/getDrawChance', body)
if res.get('success'):
println('{}, 成功领取一次抽奖机会!'.format(self.account))
break
await asyncio.sleep(2)
continue
for i in range(task['completeNum'], task['totalNum']+1):
body = {
"activityCode": self.activityCode,
"userNo": "$cooMrdGatewayUid$",
"missionNo": task['missionNo'],
}
if 'params' in task:
body['params'] = task['params']
res = await self.request(session, '/WonderfulLuckDrawApi/completeMission', [body])
if res.get('success'):
println('{}, 完成任务:{}-{}'.format(self.account, task['title'], i + 1))
await asyncio.sleep(2.5)
if flag:
await self.do_tasks(session)
async def lottery(self, session):
"""
抽奖
:return:
"""
while True:
res = await self.request(session, '/WonderfulLuckDrawApi/draw', [{
"userNo": "$cooMrdGatewayUid$",
"activityCode": self.activityCode
}])
if res.get('success'):
println('{}, 抽奖成功'.format(self.account))
else:
break
await asyncio.sleep(2)
async def run(self):
"""
:return:
"""
async with aiohttp.ClientSession(headers=self.headers, cookies=self.cookies) as session:
await self.do_tasks(session)
await self.lottery(session) # 抽奖
if __name__ == '__main__':
process_start(JdPolite, '小鸽有礼')