mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-16 17:35:37 +08:00
Add QLAPI auto-initialization for Python and format code
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
6dbd980881
commit
16b20e8b54
|
|
@ -26,7 +26,9 @@ if (typeof QLAPI === 'undefined') {
|
||||||
...client,
|
...client,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize QLAPI. Please run this script using the "task" command or add it as a scheduled task.');
|
console.error(
|
||||||
|
'Failed to initialize QLAPI. Please run this script using the "task" command or add it as a scheduled task.',
|
||||||
|
);
|
||||||
console.error('Example: task ql_sample.js');
|
console.error('Example: task ql_sample.js');
|
||||||
console.error('Error details:', error.message);
|
console.error('Error details:', error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
@ -48,11 +50,13 @@ QLAPI.getCrons({ searchValue: 'test' }).then((x) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 通过ID查询定时任务 (Get cron by ID)
|
// 通过ID查询定时任务 (Get cron by ID)
|
||||||
QLAPI.getCronById({ id: 1 }).then((x) => {
|
QLAPI.getCronById({ id: 1 })
|
||||||
console.log('getCronById', x);
|
.then((x) => {
|
||||||
}).catch((err) => {
|
console.log('getCronById', x);
|
||||||
console.log('getCronById error', err);
|
})
|
||||||
});
|
.catch((err) => {
|
||||||
|
console.log('getCronById error', err);
|
||||||
|
});
|
||||||
|
|
||||||
// 启用定时任务 (Enable cron tasks)
|
// 启用定时任务 (Enable cron tasks)
|
||||||
QLAPI.enableCrons({ ids: [1, 2] }).then((x) => {
|
QLAPI.enableCrons({ ids: [1, 2] }).then((x) => {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,35 @@ name: script name
|
||||||
cron: 1 9 * * *
|
cron: 1 9 * * *
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Initialize QLAPI if not already loaded (for direct python execution)
|
||||||
|
try:
|
||||||
|
QLAPI
|
||||||
|
except NameError:
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ql_dir = os.getenv('QL_DIR', '/ql')
|
||||||
|
preload_dir = Path(ql_dir) / 'shell' / 'preload'
|
||||||
|
|
||||||
|
# Add preload directory to Python path
|
||||||
|
sys.path.insert(0, str(preload_dir))
|
||||||
|
|
||||||
|
try:
|
||||||
|
from __ql_notify__ import send
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
class BaseApi(Client):
|
||||||
|
def notify(self, *args, **kwargs):
|
||||||
|
return send(*args, **kwargs)
|
||||||
|
|
||||||
|
QLAPI = BaseApi()
|
||||||
|
except Exception as error:
|
||||||
|
print('Failed to initialize QLAPI. Please run this script using the "task" command or add it as a scheduled task.')
|
||||||
|
print('Example: task ql_sample.py')
|
||||||
|
print(f'Error details: {error}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
print("test script")
|
print("test script")
|
||||||
print(QLAPI.notify("test script", "test desc"))
|
print(QLAPI.notify("test script", "test desc"))
|
||||||
print("test systemNotify")
|
print("test systemNotify")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user