-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathql_api.py
More file actions
51 lines (40 loc) · 1.31 KB
/
ql_api.py
File metadata and controls
51 lines (40 loc) · 1.31 KB
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
import json
import time
from typing import Tuple, Any
import requests
ql_auth_path = '/ql/config/auth.json'
# ql_auth_path = r'D:\Docker\ql\config\auth.json'
ql_url = 'http://localhost:5600'
def __get_token() -> str or None:
with open(ql_auth_path, 'r', encoding='utf-8') as f:
j_data = json.load(f)
return j_data.get('token')
def __get__headers() -> dict:
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8',
'Authorization': 'Bearer ' + __get_token()
}
return headers
# 查询任务
def get_crons(search_value: str = None) -> Tuple[bool, Any]:
params = {
't': int(time.time() * 1000)
}
if search_value is not None:
params['searchValue'] = search_value
res = requests.get(ql_url + '/api/crons', headers=__get__headers(), params=params)
j_data = res.json()
if j_data['code'] == 200:
return True, j_data['data']
return False, None
# 查询最后一条日志
def get_crons_log(cron_id: int) -> Tuple[bool, Any]:
params = {
't': int(time.time() * 1000)
}
res = requests.get(ql_url + '/api/crons/{}/log'.format(cron_id), headers=__get__headers(), params=params)
j_data = res.json()
if j_data['code'] == 200:
return True, j_data['data']
return False, None