mirror of
https://github.com/shufflewzc/faker2.git
synced 2025-04-23 10:58:44 +08:00
update
This commit is contained in:
parent
bd33a4e5ff
commit
69fbb0df93
File diff suppressed because one or more lines are too long
212
jd_identical.py
212
jd_identical.py
@ -1,212 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
"""
|
|
||||||
cron: 30 * * * *
|
|
||||||
new Env('禁用重复任务');
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
logger = logging.getLogger(name=None) # 创建一个日志对象
|
|
||||||
logging.Formatter("%(message)s") # 日志内容格式化
|
|
||||||
logger.setLevel(logging.INFO) # 设置日志等级
|
|
||||||
logger.addHandler(logging.StreamHandler()) # 添加控制台日志
|
|
||||||
# logger.addHandler(logging.FileHandler(filename="text.log", mode="w")) # 添加文件日志
|
|
||||||
|
|
||||||
|
|
||||||
ipport = os.getenv("IPPORT")
|
|
||||||
if not ipport:
|
|
||||||
logger.info(
|
|
||||||
"如果报错请在环境变量中添加你的真实 IP:端口\n名称:IPPORT\t值:127.0.0.1:5700\n或在 config.sh 中添加 export IPPORT='127.0.0.1:5700'"
|
|
||||||
)
|
|
||||||
ipport = "localhost:5700"
|
|
||||||
else:
|
|
||||||
ipport = ipport.lstrip("http://").rstrip("/")
|
|
||||||
sub_str = os.getenv("RES_SUB", "shufflewzc_faker2_main")
|
|
||||||
sub_list = sub_str.split("&")
|
|
||||||
res_only = os.getenv("RES_ONLY", True)
|
|
||||||
headers = {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_send() -> None:
|
|
||||||
logger.info("加载推送功能中...")
|
|
||||||
global send
|
|
||||||
send = None
|
|
||||||
cur_path = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
sys.path.append(cur_path)
|
|
||||||
if os.path.exists(cur_path + "/notify.py"):
|
|
||||||
try:
|
|
||||||
from notify import send
|
|
||||||
except Exception:
|
|
||||||
send = None
|
|
||||||
logger.info(f"❌加载通知服务失败!!!\n{traceback.format_exc()}")
|
|
||||||
|
|
||||||
|
|
||||||
def get_tasklist() -> list:
|
|
||||||
tasklist = []
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons?searchValue=&t={t}"
|
|
||||||
response = requests.get(url=url, headers=headers)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") == 200:
|
|
||||||
tasklist = datas.get("data")
|
|
||||||
return tasklist
|
|
||||||
|
|
||||||
|
|
||||||
def filter_res_sub(tasklist: list) -> tuple:
|
|
||||||
filter_list = []
|
|
||||||
res_list = []
|
|
||||||
for task in tasklist:
|
|
||||||
for sub in sub_list:
|
|
||||||
if task.get("command").find(sub) == -1:
|
|
||||||
flag = False
|
|
||||||
else:
|
|
||||||
flag = True
|
|
||||||
break
|
|
||||||
if flag:
|
|
||||||
res_list.append(task)
|
|
||||||
else:
|
|
||||||
filter_list.append(task)
|
|
||||||
return filter_list, res_list
|
|
||||||
|
|
||||||
|
|
||||||
def get_index(lst: list, item: str) -> list:
|
|
||||||
return [index for (index, value) in enumerate(lst) if value == item]
|
|
||||||
|
|
||||||
|
|
||||||
def get_duplicate_list(tasklist: list) -> tuple:
|
|
||||||
logger.info("\n=== 第一轮初筛开始 ===")
|
|
||||||
|
|
||||||
ids = []
|
|
||||||
names = []
|
|
||||||
cmds = []
|
|
||||||
for task in tasklist:
|
|
||||||
if flag1:
|
|
||||||
ids.append(task.get("_id"))
|
|
||||||
else:
|
|
||||||
ids.append(task.get("id"))
|
|
||||||
names.append(task.get("name"))
|
|
||||||
cmds.append(task.get("command"))
|
|
||||||
|
|
||||||
name_list = []
|
|
||||||
for i, name in enumerate(names):
|
|
||||||
if name not in name_list:
|
|
||||||
name_list.append(name)
|
|
||||||
|
|
||||||
tem_tasks = []
|
|
||||||
tem_ids = []
|
|
||||||
dup_ids = []
|
|
||||||
for name2 in name_list:
|
|
||||||
name_index = get_index(names, name2)
|
|
||||||
for i in range(len(name_index)):
|
|
||||||
if i == 0:
|
|
||||||
logger.info(f"【✅保留】{cmds[name_index[0]]}")
|
|
||||||
tem_tasks.append(tasklist[name_index[0]])
|
|
||||||
tem_ids.append(ids[name_index[0]])
|
|
||||||
else:
|
|
||||||
logger.info(f"【🚫禁用】{cmds[name_index[i]]}")
|
|
||||||
dup_ids.append(ids[name_index[i]])
|
|
||||||
logger.info("")
|
|
||||||
|
|
||||||
logger.info("=== 第一轮初筛结束 ===")
|
|
||||||
|
|
||||||
return tem_ids, tem_tasks, dup_ids
|
|
||||||
|
|
||||||
|
|
||||||
def reserve_task_only(
|
|
||||||
tem_ids: list, tem_tasks: list, dup_ids: list, res_list: list
|
|
||||||
) -> list:
|
|
||||||
if len(tem_ids) == 0:
|
|
||||||
return tem_ids
|
|
||||||
|
|
||||||
logger.info("\n=== 最终筛选开始 ===")
|
|
||||||
task3 = None
|
|
||||||
for task1 in tem_tasks:
|
|
||||||
for task2 in res_list:
|
|
||||||
if task1.get("name") == task2.get("name"):
|
|
||||||
if flag1:
|
|
||||||
dup_ids.append(task1.get("_id"))
|
|
||||||
else:
|
|
||||||
dup_ids.append(task1.get("id"))
|
|
||||||
logger.info(f"【✅保留】{task2.get('command')}")
|
|
||||||
task3 = task1
|
|
||||||
if task3:
|
|
||||||
logger.info(f"【🚫禁用】{task3.get('command')}\n")
|
|
||||||
task3 = None
|
|
||||||
logger.info("=== 最终筛选结束 ===")
|
|
||||||
return dup_ids
|
|
||||||
|
|
||||||
|
|
||||||
def disable_duplicate_tasks(ids: list) -> None:
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons/disable?t={t}"
|
|
||||||
data = json.dumps(ids)
|
|
||||||
headers["Content-Type"] = "application/json;charset=UTF-8"
|
|
||||||
response = requests.put(url=url, headers=headers, data=data)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") != 200:
|
|
||||||
logger.info(f"❌出错!!!错误信息为:{datas}")
|
|
||||||
else:
|
|
||||||
logger.info("🎉成功禁用重复任务~")
|
|
||||||
|
|
||||||
|
|
||||||
def get_token() -> str or None:
|
|
||||||
path = '/ql/config/auth.json' # 设置青龙 auth文件地址
|
|
||||||
global flag1
|
|
||||||
flag1 = True
|
|
||||||
if not os.path.isfile(path):
|
|
||||||
path = '/ql/data/config/auth.json' # 尝试设置青龙 auth 新版文件地址
|
|
||||||
flag1 = False
|
|
||||||
try:
|
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
except Exception:
|
|
||||||
logger.info(f"❌无法获取 token!!!\n{traceback.format_exc()}")
|
|
||||||
send("💔禁用重复任务失败", "无法获取 token!!!")
|
|
||||||
exit(1)
|
|
||||||
return data.get("token")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logger.info("===> 禁用重复任务开始 <===")
|
|
||||||
load_send()
|
|
||||||
token = get_token()
|
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
|
||||||
|
|
||||||
# 获取过滤后的任务列表
|
|
||||||
sub_str = "\n".join(sub_list)
|
|
||||||
logger.info(f"\n=== 你选择过滤的任务前缀为 ===\n{sub_str}")
|
|
||||||
tasklist = get_tasklist()
|
|
||||||
if len(tasklist) == 0:
|
|
||||||
logger.info("❌无法获取 tasklist!!!")
|
|
||||||
exit(1)
|
|
||||||
filter_list, res_list = filter_res_sub(tasklist)
|
|
||||||
|
|
||||||
tem_ids, tem_tasks, dup_ids = get_duplicate_list(filter_list)
|
|
||||||
# 是否在重复任务中只保留设置的前缀
|
|
||||||
if res_only:
|
|
||||||
ids = reserve_task_only(tem_ids, tem_tasks, dup_ids, res_list)
|
|
||||||
else:
|
|
||||||
ids = dup_ids
|
|
||||||
logger.info("你选择保留除了设置的前缀以外的其他任务")
|
|
||||||
|
|
||||||
sum = f"所有任务数量为:{len(tasklist)}"
|
|
||||||
filter = f"过滤的任务数量为:{len(res_list)}"
|
|
||||||
disable = f"禁用的任务数量为:{len(ids)}"
|
|
||||||
logging.info("\n=== 禁用数量统计 ===\n" + sum + "\n" + filter + "\n" + disable)
|
|
||||||
|
|
||||||
if len(ids) == 0:
|
|
||||||
logger.info("😁没有重复任务~")
|
|
||||||
else:
|
|
||||||
disable_duplicate_tasks(ids)
|
|
||||||
#if send:
|
|
||||||
#send("💖禁用重复任务成功", f"\n{sum}\n{filter}\n{disable}")
|
|
@ -1,203 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
"""
|
|
||||||
cron: 50 * * * *
|
|
||||||
new Env('禁用重复任务青龙2.11版本');
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
logger = logging.getLogger(name=None) # 创建一个日志对象
|
|
||||||
logging.Formatter("%(message)s") # 日志内容格式化
|
|
||||||
logger.setLevel(logging.INFO) # 设置日志等级
|
|
||||||
logger.addHandler(logging.StreamHandler()) # 添加控制台日志
|
|
||||||
# logger.addHandler(logging.FileHandler(filename="text.log", mode="w")) # 添加文件日志
|
|
||||||
|
|
||||||
|
|
||||||
ipport = os.getenv("IPPORT")
|
|
||||||
if not ipport:
|
|
||||||
logger.info(
|
|
||||||
"如果报错请在环境变量中添加你的真实 IP:端口\n名称:IPPORT\t值:127.0.0.1:5700\n或在 config.sh 中添加 export IPPORT='127.0.0.1:5700'"
|
|
||||||
)
|
|
||||||
ipport = "localhost:5700"
|
|
||||||
else:
|
|
||||||
ipport = ipport.lstrip("http://").rstrip("/")
|
|
||||||
sub_str = os.getenv("RES_SUB", "shufflewzc_faker2_main")
|
|
||||||
sub_list = sub_str.split("&")
|
|
||||||
res_only = os.getenv("RES_ONLY", True)
|
|
||||||
headers = {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_send() -> None:
|
|
||||||
logger.info("加载推送功能中...")
|
|
||||||
global send
|
|
||||||
send = None
|
|
||||||
cur_path = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
sys.path.append(cur_path)
|
|
||||||
if os.path.exists(cur_path + "/notify.py"):
|
|
||||||
try:
|
|
||||||
from notify import send
|
|
||||||
except Exception:
|
|
||||||
send = None
|
|
||||||
logger.info(f"❌加载通知服务失败!!!\n{traceback.format_exc()}")
|
|
||||||
|
|
||||||
|
|
||||||
def get_tasklist() -> list:
|
|
||||||
tasklist = []
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons?searchValue=&t={t}"
|
|
||||||
response = requests.get(url=url, headers=headers)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") == 200:
|
|
||||||
tasklist = datas.get("data")
|
|
||||||
return tasklist
|
|
||||||
|
|
||||||
|
|
||||||
def filter_res_sub(tasklist: list) -> tuple:
|
|
||||||
filter_list = []
|
|
||||||
res_list = []
|
|
||||||
for task in tasklist:
|
|
||||||
for sub in sub_list:
|
|
||||||
if task.get("command").find(sub) == -1:
|
|
||||||
flag = False
|
|
||||||
else:
|
|
||||||
flag = True
|
|
||||||
break
|
|
||||||
if flag:
|
|
||||||
res_list.append(task)
|
|
||||||
else:
|
|
||||||
filter_list.append(task)
|
|
||||||
return filter_list, res_list
|
|
||||||
|
|
||||||
|
|
||||||
def get_index(lst: list, item: str) -> list:
|
|
||||||
return [index for (index, value) in enumerate(lst) if value == item]
|
|
||||||
|
|
||||||
|
|
||||||
def get_duplicate_list(tasklist: list) -> tuple:
|
|
||||||
logger.info("\n=== 第一轮初筛开始 ===")
|
|
||||||
|
|
||||||
ids = []
|
|
||||||
names = []
|
|
||||||
cmds = []
|
|
||||||
for task in tasklist:
|
|
||||||
ids.append(task.get("id"))
|
|
||||||
names.append(task.get("name"))
|
|
||||||
cmds.append(task.get("command"))
|
|
||||||
|
|
||||||
name_list = []
|
|
||||||
for i, name in enumerate(names):
|
|
||||||
if name not in name_list:
|
|
||||||
name_list.append(name)
|
|
||||||
|
|
||||||
tem_tasks = []
|
|
||||||
temids = []
|
|
||||||
dupids = []
|
|
||||||
for name2 in name_list:
|
|
||||||
name_index = get_index(names, name2)
|
|
||||||
for i in range(len(name_index)):
|
|
||||||
if i == 0:
|
|
||||||
logger.info(f"【✅保留】{cmds[name_index[0]]}")
|
|
||||||
tem_tasks.append(tasklist[name_index[0]])
|
|
||||||
temids.append(ids[name_index[0]])
|
|
||||||
else:
|
|
||||||
logger.info(f"【🚫禁用】{cmds[name_index[i]]}")
|
|
||||||
dupids.append(ids[name_index[i]])
|
|
||||||
logger.info("")
|
|
||||||
|
|
||||||
logger.info("=== 第一轮初筛结束 ===")
|
|
||||||
|
|
||||||
return temids, tem_tasks, dupids
|
|
||||||
|
|
||||||
|
|
||||||
def reserve_task_only(
|
|
||||||
temids: list, tem_tasks: list, dupids: list, res_list: list
|
|
||||||
) -> list:
|
|
||||||
if len(temids) == 0:
|
|
||||||
return temids
|
|
||||||
|
|
||||||
logger.info("\n=== 最终筛选开始 ===")
|
|
||||||
task3 = None
|
|
||||||
for task1 in tem_tasks:
|
|
||||||
for task2 in res_list:
|
|
||||||
if task1.get("name") == task2.get("name"):
|
|
||||||
dupids.append(task1.get("id"))
|
|
||||||
logger.info(f"【✅保留】{task2.get('command')}")
|
|
||||||
task3 = task1
|
|
||||||
if task3:
|
|
||||||
logger.info(f"【🚫禁用】{task3.get('command')}\n")
|
|
||||||
task3 = None
|
|
||||||
logger.info("=== 最终筛选结束 ===")
|
|
||||||
return dupids
|
|
||||||
|
|
||||||
|
|
||||||
def disable_duplicate_tasks(ids: list) -> None:
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons/disable?t={t}"
|
|
||||||
data = json.dumps(ids)
|
|
||||||
headers["Content-Type"] = "application/json;charset=UTF-8"
|
|
||||||
response = requests.put(url=url, headers=headers, data=data)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") != 200:
|
|
||||||
logger.info(f"❌出错!!!错误信息为:{datas}")
|
|
||||||
else:
|
|
||||||
logger.info("🎉成功禁用重复任务~")
|
|
||||||
|
|
||||||
|
|
||||||
def get_token() -> str or None:
|
|
||||||
try:
|
|
||||||
path = '/ql/config/auth.json' # 设置青龙 auth文件地址
|
|
||||||
if not os.path.isfile(path):
|
|
||||||
path = '/ql/data/config/auth.json' # 尝试设置青龙 auth 新版文件地址
|
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
except Exception:
|
|
||||||
logger.info(f"❌无法获取 token!!!\n{traceback.format_exc()}")
|
|
||||||
send("💔禁用重复任务失败", "无法获取 token!!!")
|
|
||||||
exit(1)
|
|
||||||
return data.get("token")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logger.info("===> 禁用重复任务开始 <===")
|
|
||||||
load_send()
|
|
||||||
token = get_token()
|
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
|
||||||
|
|
||||||
# 获取过滤后的任务列表
|
|
||||||
sub_str = "\n".join(sub_list)
|
|
||||||
logger.info(f"\n=== 你选择过滤的任务前缀为 ===\n{sub_str}")
|
|
||||||
tasklist = get_tasklist()
|
|
||||||
if len(tasklist) == 0:
|
|
||||||
logger.info("❌无法获取 tasklist!!!")
|
|
||||||
exit(1)
|
|
||||||
filter_list, res_list = filter_res_sub(tasklist)
|
|
||||||
|
|
||||||
temids, tem_tasks, dupids = get_duplicate_list(filter_list)
|
|
||||||
# 是否在重复任务中只保留设置的前缀
|
|
||||||
if res_only:
|
|
||||||
ids = reserve_task_only(temids, tem_tasks, dupids, res_list)
|
|
||||||
else:
|
|
||||||
ids = dupids
|
|
||||||
logger.info("你选择保留除了设置的前缀以外的其他任务")
|
|
||||||
|
|
||||||
sum = f"所有任务数量为:{len(tasklist)}"
|
|
||||||
filter = f"过滤的任务数量为:{len(res_list)}"
|
|
||||||
disable = f"禁用的任务数量为:{len(ids)}"
|
|
||||||
logging.info("\n=== 禁用数量统计 ===\n" + sum + "\n" + filter + "\n" + disable)
|
|
||||||
|
|
||||||
if len(ids) == 0:
|
|
||||||
logger.info("😁没有重复任务~")
|
|
||||||
else:
|
|
||||||
disable_duplicate_tasks(ids)
|
|
||||||
if send:
|
|
||||||
send("💖禁用重复任务成功", f"\n{sum}\n{filter}\n{disable}")
|
|
@ -1,203 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
"""
|
|
||||||
cron: 50 * * * *
|
|
||||||
new Env('禁用重复任务青龙2.14版本');
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
logger = logging.getLogger(name=None) # 创建一个日志对象
|
|
||||||
logging.Formatter("%(message)s") # 日志内容格式化
|
|
||||||
logger.setLevel(logging.INFO) # 设置日志等级
|
|
||||||
logger.addHandler(logging.StreamHandler()) # 添加控制台日志
|
|
||||||
# logger.addHandler(logging.FileHandler(filename="text.log", mode="w")) # 添加文件日志
|
|
||||||
|
|
||||||
|
|
||||||
ipport = os.getenv("IPPORT")
|
|
||||||
if not ipport:
|
|
||||||
logger.info(
|
|
||||||
"如果报错请在环境变量中添加你的真实 IP:端口\n名称:IPPORT\t值:127.0.0.1:5700\n或在 config.sh 中添加 export IPPORT='127.0.0.1:5700'"
|
|
||||||
)
|
|
||||||
ipport = "localhost:5700"
|
|
||||||
else:
|
|
||||||
ipport = ipport.lstrip("http://").rstrip("/")
|
|
||||||
sub_str = os.getenv("RES_SUB", "shufflewzc_faker2_main")
|
|
||||||
sub_list = sub_str.split("&")
|
|
||||||
res_only = os.getenv("RES_ONLY", True)
|
|
||||||
headers = {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_send() -> None:
|
|
||||||
logger.info("加载推送功能中...")
|
|
||||||
global send
|
|
||||||
send = None
|
|
||||||
cur_path = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
sys.path.append(cur_path)
|
|
||||||
if os.path.exists(cur_path + "/notify.py"):
|
|
||||||
try:
|
|
||||||
from notify import send
|
|
||||||
except Exception:
|
|
||||||
send = None
|
|
||||||
logger.info(f"❌加载通知服务失败!!!\n{traceback.format_exc()}")
|
|
||||||
|
|
||||||
|
|
||||||
def get_tasklist() -> list:
|
|
||||||
tasklist = []
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons?searchValue=&t={t}"
|
|
||||||
response = requests.get(url=url, headers=headers)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") == 200:
|
|
||||||
tasklist = datas.get("data")
|
|
||||||
return tasklist
|
|
||||||
|
|
||||||
|
|
||||||
def filter_res_sub(tasklist: list) -> tuple:
|
|
||||||
filter_list = []
|
|
||||||
res_list = []
|
|
||||||
for task in tasklist['data']:
|
|
||||||
for sub in sub_list:
|
|
||||||
if task.get("command").find(sub) == -1:
|
|
||||||
flag = False
|
|
||||||
else:
|
|
||||||
flag = True
|
|
||||||
break
|
|
||||||
if flag:
|
|
||||||
res_list.append(task)
|
|
||||||
else:
|
|
||||||
filter_list.append(task)
|
|
||||||
return filter_list, res_list
|
|
||||||
|
|
||||||
|
|
||||||
def get_index(lst: list, item: str) -> list:
|
|
||||||
return [index for (index, value) in enumerate(lst) if value == item]
|
|
||||||
|
|
||||||
|
|
||||||
def get_duplicate_list(tasklist: list) -> tuple:
|
|
||||||
logger.info("\n=== 第一轮初筛开始 ===")
|
|
||||||
|
|
||||||
ids = []
|
|
||||||
names = []
|
|
||||||
cmds = []
|
|
||||||
for task in tasklist:
|
|
||||||
ids.append(task.get("id"))
|
|
||||||
names.append(task.get("name"))
|
|
||||||
cmds.append(task.get("command"))
|
|
||||||
|
|
||||||
name_list = []
|
|
||||||
for i, name in enumerate(names):
|
|
||||||
if name not in name_list:
|
|
||||||
name_list.append(name)
|
|
||||||
|
|
||||||
tem_tasks = []
|
|
||||||
temids = []
|
|
||||||
dupids = []
|
|
||||||
for name2 in name_list:
|
|
||||||
name_index = get_index(names, name2)
|
|
||||||
for i in range(len(name_index)):
|
|
||||||
if i == 0:
|
|
||||||
logger.info(f"【✅保留】{cmds[name_index[0]]}")
|
|
||||||
tem_tasks.append(tasklist[name_index[0]])
|
|
||||||
temids.append(ids[name_index[0]])
|
|
||||||
else:
|
|
||||||
logger.info(f"【🚫禁用】{cmds[name_index[i]]}")
|
|
||||||
dupids.append(ids[name_index[i]])
|
|
||||||
logger.info("")
|
|
||||||
|
|
||||||
logger.info("=== 第一轮初筛结束 ===")
|
|
||||||
|
|
||||||
return temids, tem_tasks, dupids
|
|
||||||
|
|
||||||
|
|
||||||
def reserve_task_only(
|
|
||||||
temids: list, tem_tasks: list, dupids: list, res_list: list
|
|
||||||
) -> list:
|
|
||||||
if len(temids) == 0:
|
|
||||||
return temids
|
|
||||||
|
|
||||||
logger.info("\n=== 最终筛选开始 ===")
|
|
||||||
task3 = None
|
|
||||||
for task1 in tem_tasks:
|
|
||||||
for task2 in res_list:
|
|
||||||
if task1.get("name") == task2.get("name"):
|
|
||||||
dupids.append(task1.get("id"))
|
|
||||||
logger.info(f"【✅保留】{task2.get('command')}")
|
|
||||||
task3 = task1
|
|
||||||
if task3:
|
|
||||||
logger.info(f"【🚫禁用】{task3.get('command')}\n")
|
|
||||||
task3 = None
|
|
||||||
logger.info("=== 最终筛选结束 ===")
|
|
||||||
return dupids
|
|
||||||
|
|
||||||
|
|
||||||
def disable_duplicate_tasks(ids: list) -> None:
|
|
||||||
t = round(time.time() * 1000)
|
|
||||||
url = f"http://{ipport}/api/crons/disable?t={t}"
|
|
||||||
data = json.dumps(ids)
|
|
||||||
headers["Content-Type"] = "application/json;charset=UTF-8"
|
|
||||||
response = requests.put(url=url, headers=headers, data=data)
|
|
||||||
datas = json.loads(response.content.decode("utf-8"))
|
|
||||||
if datas.get("code") != 200:
|
|
||||||
logger.info(f"❌出错!!!错误信息为:{datas}")
|
|
||||||
else:
|
|
||||||
logger.info("🎉成功禁用重复任务~")
|
|
||||||
|
|
||||||
|
|
||||||
def get_token() -> str or None:
|
|
||||||
try:
|
|
||||||
path = '/ql/config/auth.json' # 设置青龙 auth文件地址
|
|
||||||
if not os.path.isfile(path):
|
|
||||||
path = '/ql/data/config/auth.json' # 尝试设置青龙 auth 新版文件地址
|
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
except Exception:
|
|
||||||
logger.info(f"❌无法获取 token!!!\n{traceback.format_exc()}")
|
|
||||||
send("💔禁用重复任务失败", "无法获取 token!!!")
|
|
||||||
exit(1)
|
|
||||||
return data.get("token")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logger.info("===> 禁用重复任务开始 <===")
|
|
||||||
load_send()
|
|
||||||
token = get_token()
|
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
|
||||||
|
|
||||||
# 获取过滤后的任务列表
|
|
||||||
sub_str = "\n".join(sub_list)
|
|
||||||
logger.info(f"\n=== 你选择过滤的任务前缀为 ===\n{sub_str}")
|
|
||||||
tasklist = get_tasklist()
|
|
||||||
if len(tasklist) == 0:
|
|
||||||
logger.info("❌无法获取 tasklist!!!")
|
|
||||||
exit(1)
|
|
||||||
filter_list, res_list = filter_res_sub(tasklist)
|
|
||||||
|
|
||||||
temids, tem_tasks, dupids = get_duplicate_list(filter_list)
|
|
||||||
# 是否在重复任务中只保留设置的前缀
|
|
||||||
if res_only:
|
|
||||||
ids = reserve_task_only(temids, tem_tasks, dupids, res_list)
|
|
||||||
else:
|
|
||||||
ids = dupids
|
|
||||||
logger.info("你选择保留除了设置的前缀以外的其他任务")
|
|
||||||
|
|
||||||
sum = f"所有任务数量为:{len(tasklist)}"
|
|
||||||
filter = f"过滤的任务数量为:{len(res_list)}"
|
|
||||||
disable = f"禁用的任务数量为:{len(ids)}"
|
|
||||||
logging.info("\n=== 禁用数量统计 ===\n" + sum + "\n" + filter + "\n" + disable)
|
|
||||||
|
|
||||||
if len(ids) == 0:
|
|
||||||
logger.info("😁没有重复任务~")
|
|
||||||
else:
|
|
||||||
disable_duplicate_tasks(ids)
|
|
||||||
if send:
|
|
||||||
send("💖禁用重复任务成功", f"\n{sum}\n{filter}\n{disable}")
|
|
180
jd_jdkd1.js
180
jd_jdkd1.js
@ -1,180 +0,0 @@
|
|||||||
/*
|
|
||||||
京东快递
|
|
||||||
@Leaf
|
|
||||||
|
|
||||||
30 16 * * * jd_jdkd1.js
|
|
||||||
|
|
||||||
*/
|
|
||||||
const $ = new Env('京东快递');
|
|
||||||
const got = require('got');
|
|
||||||
|
|
||||||
const envSplitor = ['&','\n','@']
|
|
||||||
const ckNames = ['JD_COOKIE']
|
|
||||||
|
|
||||||
const MAX_THREAD = parseInt(process.env['jd_jdkd_thread']) || 5
|
|
||||||
const DEFAULT_TIMEOUT=8000, DEFAULT_RETRY=3;
|
|
||||||
|
|
||||||
const default_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.31(0x18001f2f) NetType/WIFI Language/zh_CN miniProgram/wx73247c7819d61796'
|
|
||||||
const Referer = 'https://jingcai-h5.jd.com/'
|
|
||||||
const Origin = 'https://jingcai-h5.jd.com'
|
|
||||||
|
|
||||||
const client = got.extend({
|
|
||||||
headers:{
|
|
||||||
Connection:'keep-alive',
|
|
||||||
'User-Agent': default_UA,
|
|
||||||
Referer,
|
|
||||||
Origin,
|
|
||||||
AppParams: JSON.stringify({"appid":158,"ticket_type":"m"}),
|
|
||||||
ClientInfo: JSON.stringify({"appName":"jingcai","client":"m"}),
|
|
||||||
'LOP-DN': 'jingcai.jd.com',
|
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
|
||||||
},
|
|
||||||
retry: {limit:0},
|
|
||||||
timeout: DEFAULT_TIMEOUT,
|
|
||||||
followRedirect: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
class BasicClass{constructor(){this.index=$.userIdx++;this.name='';} log(msg,opt={}){var m='',n=$.userCount.toString().length;;if(this.index)m+=`账号[${$.padStr(this.index,n)}]`;if(this.name)m+=`[${this.name}]`;$.log(m+msg,opt);} async request(opt){var resp=null,count=0;var fn=opt.fn||opt.url;opt.method=opt?.method?.toUpperCase()||'GET';while(count++<DEFAULT_RETRY){try{await client(opt).then(t=>{resp=t},e=>{resp=e.response});if(((resp?.statusCode/100)|0)<=4)break;}catch(e){if(e.name=='TimeoutError'){this.log(`[${fn}]请求超时,重试第${count}次`);}else{this.log(`[${fn}]请求错误(${e.message}),重试第${count}次`);}};} if(resp==null)return Promise.resolve({statusCode:-1,headers:null,result:null});let{statusCode,headers,body}=resp;if(body)try{body=JSON.parse(body);}catch{};return Promise.resolve({statusCode,headers,result:body})}}
|
|
||||||
let http = new BasicClass();
|
|
||||||
|
|
||||||
class UserClass extends BasicClass {
|
|
||||||
constructor(ck) {
|
|
||||||
super()
|
|
||||||
this.cookie = ck
|
|
||||||
this.pt_pin = ck.match(/pin=([\w\-\%]+)/) ? ck.match(/pin=([\w\-\%]+)/)[1] : ''
|
|
||||||
this.name = decodeURIComponent(this.pt_pin)
|
|
||||||
}
|
|
||||||
|
|
||||||
async queryTaskList() {
|
|
||||||
try {
|
|
||||||
let options = {
|
|
||||||
fn: 'queryTaskList',
|
|
||||||
method: 'post',
|
|
||||||
url: 'https://lop-proxy.jd.com/ESGApi/queryTaskList',
|
|
||||||
headers: {Cookie:this.cookie,'event-id':$.randomPattern('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx')},
|
|
||||||
json: [{"pin":"$cooMrdGatewayUid$"}],
|
|
||||||
}
|
|
||||||
let {result} = await this.request(options)
|
|
||||||
let code = result?.code
|
|
||||||
if(code == 1) {
|
|
||||||
for(let task of (result?.content?.taskInfoList||[]).filter(x => x.taskReachNum < x.taskNeedReachNum && x.triggerType==1)) {
|
|
||||||
await this.reachTaskInfo(task);
|
|
||||||
await $.wait(1000);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let errCode = code || result?.error_response?.code
|
|
||||||
let errMsg = result?.msg || result?.error_response?.zh_desc
|
|
||||||
this.log(`查询任务列表出错[${errCode}]: ${errMsg}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
$.log(e)
|
|
||||||
} finally {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async reachTaskInfo(task) {
|
|
||||||
try {
|
|
||||||
let options = {
|
|
||||||
fn: 'reachTaskInfo',
|
|
||||||
method: 'post',
|
|
||||||
url: 'https://lop-proxy.jd.com/ESGApi/reachTaskInfo',
|
|
||||||
headers: {Cookie:this.cookie,'event-id':$.randomPattern('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx')},
|
|
||||||
json: [{
|
|
||||||
taskNo: task.taskNo,
|
|
||||||
childTaskId: task.childTaskId,
|
|
||||||
pin: "$cooMrdGatewayUid$",
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
let {result} = await this.request(options)
|
|
||||||
let code = result?.code
|
|
||||||
if(code == 1) {
|
|
||||||
this.log(`完成任务[${task.taskTitle}]成功`);
|
|
||||||
await $.wait(1000);
|
|
||||||
await this.queryTaskList();
|
|
||||||
} else {
|
|
||||||
let errCode = code || result?.error_response?.code
|
|
||||||
let errMsg = result?.msg || result?.error_response?.zh_desc
|
|
||||||
this.log(`完成任务[${task.taskTitle}]失败[${errCode}]: ${errMsg}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
$.log(e)
|
|
||||||
} finally {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async queryCanGetRewardTaskList() {
|
|
||||||
try {
|
|
||||||
let options = {
|
|
||||||
fn: 'queryCanGetRewardTaskList',
|
|
||||||
method: 'post',
|
|
||||||
url: 'https://lop-proxy.jd.com/ESGApi/queryCanGetRewardTaskList',
|
|
||||||
headers: {Cookie:this.cookie,'event-id':$.randomPattern('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx')},
|
|
||||||
json: [{"pin":"$cooMrdGatewayUid$"}],
|
|
||||||
}
|
|
||||||
let {result} = await this.request(options)
|
|
||||||
let code = result?.code
|
|
||||||
if(code == 1) {
|
|
||||||
for(let item of (result?.content?.personalCarbonRewardRespDtoList||[])) {
|
|
||||||
await this.operationPersonalCarbonIntegral(item)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let errCode = code || result?.error_response?.code
|
|
||||||
let errMsg = result?.msg || result?.error_response?.zh_desc
|
|
||||||
this.log(`查询可领取奖励出错[${errCode}]: ${errMsg}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
$.log(e)
|
|
||||||
} finally {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async operationPersonalCarbonIntegral(item) {
|
|
||||||
try {
|
|
||||||
let options = {
|
|
||||||
fn: 'operationPersonalCarbonIntegral',
|
|
||||||
method: 'post',
|
|
||||||
url: 'https://lop-proxy.jd.com/ESGApi/operationPersonalCarbonIntegral',
|
|
||||||
headers: {Cookie:this.cookie,'event-id':$.randomPattern('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx')},
|
|
||||||
json: [{
|
|
||||||
type: 2,
|
|
||||||
operationType: 1,
|
|
||||||
rewardNo: item.rewardNo,
|
|
||||||
taskNo: item.taskNo,
|
|
||||||
pin: "$cooMrdGatewayUid$",
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
let {result} = await this.request(options)
|
|
||||||
let code = result?.code
|
|
||||||
if(code == 1) {
|
|
||||||
this.log(`收取[${item.taskTitle}]奖励成功, 现在有${result?.content?.carbonIntegral}g能量`)
|
|
||||||
} else {
|
|
||||||
let errCode = code || result?.error_response?.code
|
|
||||||
let errMsg = result?.msg || result?.error_response?.zh_desc
|
|
||||||
this.log(`收取[${item.taskTitle}]奖励失败[${errCode}]: ${errMsg}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
$.log(e)
|
|
||||||
} finally {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async userTask() {
|
|
||||||
await this.queryTaskList();
|
|
||||||
await this.queryCanGetRewardTaskList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
!(async () => {
|
|
||||||
$.read_env(UserClass);
|
|
||||||
|
|
||||||
await $.threadTask('userTask',MAX_THREAD)
|
|
||||||
})()
|
|
||||||
.catch((e) => $.log(e))
|
|
||||||
.finally(() => $.exitNow())
|
|
||||||
|
|
||||||
function Env(name){return new class{constructor(name){this.name=name;this.startTime=Date.now();this.log(`[${this.name}]开始运行\n`,{time:true});this.notifyStr=[];this.notifyFlag=true;this.userIdx=0;this.userList=[];this.userCount=0;} log(msg,options={}){let opt={console:true};Object.assign(opt,options);if(opt.time){let fmt=opt.fmt||'hh:mm:ss';msg=`[${this.time(fmt)}]`+msg;} if(opt.notify)this.notifyStr.push(msg);if(opt.console)console.log(msg);} read_env(Class){let envStrList=ckNames.map(x=>process.env[x]);for(let env_str of envStrList.filter(x=>!!x)){let sp=envSplitor.filter(x=>env_str.includes(x));let splitor=sp.length>0?sp[0]:envSplitor[0];for(let ck of env_str.split(splitor).filter(x=>!!x)){this.userList.push(new Class(ck));}} this.userCount=this.userList.length;if(!this.userCount){this.log(`未找到变量,请检查变量${ckNames.map(x => '['+x+']').join('或')}`,{notify:true});return false;} this.log(`共找到${this.userCount}个账号`);return true;} async threads(taskName,conf,opt={}){while(conf.idx<$.userList.length){let user=$.userList[conf.idx++];await user[taskName](opt);}} async threadTask(taskName,thread){let taskAll=[];let taskConf={idx:0};while(thread--)taskAll.push(this.threads(taskName,taskConf));await Promise.all(taskAll);} time(t,x=null){let xt=x?new Date(x):new Date;let e={"M+":xt.getMonth()+1,"d+":xt.getDate(),"h+":xt.getHours(),"m+":xt.getMinutes(),"s+":xt.getSeconds(),"q+":Math.floor((xt.getMonth()+3)/3),S:this.padStr(xt.getMilliseconds(),3)};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(xt.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).length)));return t;} async showmsg(){if(!this.notifyFlag)return;if(!this.notifyStr.length)return;var notify=require('./sendNotify');this.log('\n============== 推送 ==============');await notify.sendNotify(this.name,this.notifyStr.join('\n'));} padStr(num,length,opt={}){let padding=opt.padding||'0';let mode=opt.mode||'l';let numStr=String(num);let numPad=(length>numStr.length)?(length-numStr.length):0;let pads='';for(let i=0;i<numPad;i++){pads+=padding;} if(mode=='r'){numStr=numStr+pads;}else{numStr=pads+numStr;} return numStr;} json2str(obj,c,encode=false){let ret=[];for(let keys of Object.keys(obj).sort()){let v=obj[keys];if(v&&encode)v=encodeURIComponent(v);ret.push(keys+'='+v);} return ret.join(c);} str2json(str,decode=false){let ret={};for(let item of str.split('&')){if(!item)continue;let idx=item.indexOf('=');if(idx==-1)continue;let k=item.substr(0,idx);let v=item.substr(idx+1);if(decode)v=decodeURIComponent(v);ret[k]=v;} return ret;} randomPattern(pattern,charset='abcdef0123456789'){let str='';for(let chars of pattern){if(chars=='x'){str+=charset.charAt(Math.floor(Math.random()*charset.length));}else if(chars=='X'){str+=charset.charAt(Math.floor(Math.random()*charset.length)).toUpperCase();}else{str+=chars;}} return str;} randomString(len,charset='abcdef0123456789'){let str='';for(let i=0;i<len;i++){str+=charset.charAt(Math.floor(Math.random()*charset.length));} return str;} randomList(a){let idx=Math.floor(Math.random()*a.length);return a[idx];} wait(t){return new Promise(e=>setTimeout(e,t));} async exitNow(){await this.showmsg();let e=Date.now();let s=(e-this.startTime)/1000;this.log('');this.log(`[${this.name}]运行结束,共运行了${s}秒`,{time:true});process.exit(0);}} (name)}
|
|
10
jd_jjqdtx.js
10
jd_jjqdtx.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
12
jd_ttlhb.js
12
jd_ttlhb.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
19
jd_unFollow1.js
Normal file
19
jd_unFollow1.js
Normal file
File diff suppressed because one or more lines are too long
13
jd_xbhdl.js
13
jd_xbhdl.js
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user