本文主要是介绍青龙面板脚本去重,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
懒人一键上车地址:https://jd.funyhook.com
1、创建新定时任务
进入qinglong/ql/script/目录
2、新建去重脚本jd_disable.js
# -*- coding:utf-8 -*-
'''
cron: 20 10 */7 * *
new Env('禁用重复任务');
'''import json
import os, sys
import requests
import timeip="localhost"
//填写你要保留的脚本的前缀
substr="cdle_carry" def loadSend():print("加载推送功能")global sendsend = Nonecur_path = os.path.abspath(os.path.dirname(__file__))sys.path.append(cur_path)if os.path.exists(cur_path + "/sendNotify.py"):try:from sendNotify import sendexcept Exception as e:send = Noneprint("加载通知服务失败~",e)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 getTaskList():t = round(time.time() * 1000)url = "http://%s:5700/api/crons?searchValue=&t=%d" % (ip, t)response = requests.get(url=url, headers=headers)responseContent=json.loads(response.content.decode('utf-8'))if responseContent['code']==200:taskList= responseContent['data']return taskListelse:# 没有获取到taskList,返回空return []def getDuplicate(taskList):wholeNames={}duplicateID=[]taskListTemp=[]for index in range(len(taskList)):task=taskList[index]if task['name'] in wholeNames.keys() and task['command'].find(substr) < 0:duplicateID.append(task['_id'])else:taskListTemp.append(task)wholeNames[task['name']] = 1#print(taskListTemp)return getDuplicateCommon(taskListTemp,duplicateID)def getDuplicateCommon(taskListTemp,duplicateID):#if len(duplicateID)==0:# return duplicateIDduplicateIDTemp=[]for task in taskListTemp:for taskTemp in taskListTemp:if task['_id'] != taskTemp['_id'] and task['name'] == taskTemp['name'] and task['command'].find(substr) < 0:duplicateID.append(task['_id'])return duplicateIDdef getData(duplicateID):rawData = "["count=0for id in duplicateID:rawData += ""%s""%idif count<len(duplicateID)-1:rawData += ", "count+=1rawData += "]"return rawDatadef disableDuplicateTasks(duplicateID):t = round(time.time() * 1000)url = "http://%s:5700/api/crons/disable?t=%d" % (ip, t)data=json.dumps(duplicateID)headers["Content-Type"]="application/json;charset=UTF-8"response=requests.put(url=url,headers=headers,data=data)msg = json.loads(response.content.decode('utf-8'))if msg['code']!=200:print("出错!,错误信息为:%s"%msg)else:print("成功禁用重复任务")def loadToken():# cur_path = os.path.abspath(os.path.dirname(__file__))# send("当前路径:",cur_path)try:with open("/ql/config/auth.json","r",encoding="utf-8") as f:data=json.load(f)except:
这篇关于青龙面板脚本去重的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!