酷Q:https://cqp.cc/ CoolQ HTTP API 插件:https://github.com/richardchien/coolq-http-api 将HTTP API插件放置于app文件夹中,启动并登陆酷Q,在菜单中启用插件。 HTTP API插件的默认地址为http://localhost:5700/
2.安装cqhttp包
1
pip install cqhttp
安装后在Python中使用:
1 2 3
from cqhttp import CQHttp bot = CQHttp(api_root='http://219.228.63.56:5700/') bot.send_group_msg(group_id=599070209,message='hello world')
第二行定义了一个机器人,第三行让这个机器人发一条hello world的消息。
开始编写程序
1.获取任务状态
1 2 3 4 5 6
import subprocess as sp classCQJobMonitor(): defjobstate(self): states=sp.check_output(self.command.split()).decode('utf-8').split("\n") states=[' '.join(line.split()) for line in states ifany([keyword in line for keyword inself.keywords])] return states
defjobstate(self): states=sp.check_output(self.command.split()).decode('utf-8').split("\n") states=[' '.join(line.split()) for line in states ifany([keyword in line for keyword inself.keywords])] return states
from CQJobMonitor import CQJobMonitor CQJobMonitor(command="qstat",cqroot='http://219.228.63.56:5700/',group_id=312676525,keywords=['jzzeng'],timeinterval=300).loopmonitor()