Ai
2 Star 1 Fork 1

Charles/github_ClassmateLin_jd_scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jd_collar_bean.py 4.54 KB
一键复制 编辑 原始数据 按行查看 历史
ClassmateLin 提交于 2021-09-14 17:22 +08:00 . 修复助力池/删除过期脚本
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# @Time : 2021/7/26 9:55 上午
# @File : jd_collar_bean.py
# @Project : jd_scripts
# @Cron : 6 1 * * *
# @Desc : 京东APP首页->领京豆->升级赚京豆
import json
import math
import random
import asyncio
import aiohttp
from urllib.parse import quote
from utils.console import println
from utils.logger import logger
from utils.jd_init import jd_init
from config import USER_AGENT
def random_string(e=40):
"""
生成随机字符串
:param e:
:return:
"""
t = "abcdefhijkmnprstwxyz123456789"
len_ = len(t)
s = ""
for i in range(e):
s += t[math.floor(random.random() * len_)]
return s
@jd_init
class JdCollarBean:
"""
领京豆
"""
headers = {
'User-Agent': USER_AGENT,
'Host': 'api.m.jd.com',
'Connection': 'keep-alive',
'Accept-Language': 'zh-cn',
'Referer': 'https://h5.m.jd.com/rn/42yjy8na6pFsq1cx9MJQ5aTgu3kX/index.html',
}
id = random_string(40)
async def request(self, session, function_id='', body=None, method='GET'):
"""
请求数据
:return:
"""
try:
if not body:
body = {}
url = 'https://api.m.jd.com/client.action?' \
'functionId={}&body={}&appid=ld&client=m&' \
'uuid={}&openudid={}'.format(function_id, quote(json.dumps(body)), self.id, self.id)
if method == 'GET':
response = await session.get(url)
else:
response = await session.post(url)
text = await response.text()
data = json.loads(text)
return data
except Exception as e:
println('{}, 获取数据失败:{}!'.format(self.account, e.args))
@logger.catch
async def do_task(self, session):
"""
做任务
:param session:
:return:
"""
data = await self.request(session, 'beanTaskList', {"viewChannel": "AppHome"})
if data['code'] != '0':
println('{}, 获取任务失败!'.format(self.account))
return
data = data['data']
if not data['viewAppHome']['takenTask']:
await self.request(session, 'beanHomeIconDoTask', {"flag": "0", "viewChannel": "AppHome"})
await asyncio.sleep(1)
if not data['viewAppHome']['doneTask']:
await self.request(session, 'beanHomeIconDoTask', {"flag": "1", "viewChannel": "AppHome"})
await asyncio.sleep(1)
for task in data['taskInfos']:
task_name = task['taskName']
if task['status'] == 2: # 任务已完成
continue
if task['taskType'] == 3:
action_type = 0
else:
action_type = 1
res = await self.request(session, 'beanDoTask', {
"actionType": action_type,
"taskToken": task['subTaskVOS'][0]['taskToken']
})
if 'errorCode' in res:
println('{}, 任务:{}, {}'.format(self.account, task_name, res['errorMessage']))
elif 'data' in res and 'bizMsg' in res['data']:
println('{}, 任务:{}, {}'.format(self.account, task_name, res['data']['bizMsg']))
else:
println('{}, 任务:{}, {}'.format(self.account, task_name, res))
if task['taskType'] != 3:
await asyncio.sleep(3)
res = await self.request(session, 'beanDoTask',
{"actionType": 0, "taskToken": task['subTaskVOS'][0]['taskToken']})
if 'data' in res and 'bizMsg' in res['data']:
println('{}, 任务:{}, {}'.format(self.account, task_name, res['data']['bizMsg']))
elif 'errorCode' in res:
println('{}, 任务:{}, {}'.format(self.account, task_name, res['errorMessage']))
else:
println('{}, 任务:{}, {}'.format(self.account, task_name, res))
await asyncio.sleep(1)
async def run(self):
"""
入口
:return:
"""
async with aiohttp.ClientSession(headers=self.headers, cookies=self.cookies) as session:
println('{}, 正在做任务!'.format(self.account))
for i in range(3):
await self.do_task(session)
println('{}, 任务已做完!'.format(self.account))
if __name__ == '__main__':
from utils.process import process_start
process_start(JdCollarBean, '领京豆')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ritaswc/ClassmateLin_jd_scripts.git
git@gitee.com:ritaswc/ClassmateLin_jd_scripts.git
ritaswc
ClassmateLin_jd_scripts
github_ClassmateLin_jd_scripts
develop

搜索帮助