parent
664d6e352d
commit
41877bd6a4
5 changed files with 374 additions and 0 deletions
@ -0,0 +1,95 @@ |
|||||||
|
# Chinese Almanac (黄历) Skill |
||||||
|
|
||||||
|
## 功能说明 |
||||||
|
|
||||||
|
使用 Tavily AI Search API 查询中国传统黄历信息,提供: |
||||||
|
- ✅ 每日宜忌查询 |
||||||
|
- ✅ 农历日期转换 |
||||||
|
- ✅ 冲煞信息 |
||||||
|
- ✅ 抗反爬虫保护(通过 Tavily API) |
||||||
|
|
||||||
|
## 架构 |
||||||
|
|
||||||
|
``` |
||||||
|
用户查询 → Tavily API → 权威黄历网站 → 解析结果 → 返回给用户 |
||||||
|
``` |
||||||
|
|
||||||
|
**优势:** |
||||||
|
- Tavily API 处理反爬虫,避免直接访问被阻止 |
||||||
|
- AI 优化搜索结果,提取准确信息 |
||||||
|
- 内置 fallback 数据,API 失败时仍有基础信息 |
||||||
|
|
||||||
|
## 配置 |
||||||
|
|
||||||
|
编辑 `/root/.openclaw-life/openclaw.json`: |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"skills": { |
||||||
|
"entries": { |
||||||
|
"chinese-almanac": { |
||||||
|
"enabled": true, |
||||||
|
"config": { |
||||||
|
"tavily_api_key": "tvly-dev-xxx" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
## 使用方式 |
||||||
|
|
||||||
|
### Telegram 命令 |
||||||
|
``` |
||||||
|
/almanac # 查询明天黄历 |
||||||
|
/almanac 2026-02-24 # 查询指定日期 |
||||||
|
``` |
||||||
|
|
||||||
|
### 自然语言查询 |
||||||
|
``` |
||||||
|
明天黄历如何? |
||||||
|
2 月 24 日适合搬家吗? |
||||||
|
查询后天宜忌 |
||||||
|
``` |
||||||
|
|
||||||
|
### 编程接口 |
||||||
|
```javascript |
||||||
|
const { queryAlmanac, formatAlmanac } = require('./almanac.js'); |
||||||
|
|
||||||
|
const result = await queryAlmanac('2026-02-24'); |
||||||
|
console.log(formatAlmanac(result)); |
||||||
|
``` |
||||||
|
|
||||||
|
## 返回数据格式 |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"success": true, |
||||||
|
"date": "2026-02-24", |
||||||
|
"lunarDate": "农历正月初八", |
||||||
|
"weekday": "星期二", |
||||||
|
"yi": ["开市", "交易", "入宅", "移徙"], |
||||||
|
"ji": ["嫁娶", "栽种", "安葬"], |
||||||
|
"chong": "冲鸡 煞西" |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
## Fallback 机制 |
||||||
|
|
||||||
|
当 Tavily API 不可用时,自动使用传统历法推算的基础数据: |
||||||
|
- 农历日期(基于公历计算) |
||||||
|
- 基础宜忌(传统吉日规律) |
||||||
|
- 冲煞信息(干支纪年) |
||||||
|
|
||||||
|
## 依赖 |
||||||
|
|
||||||
|
- Tavily API Key (已配置) |
||||||
|
- Node.js fetch API (内置) |
||||||
|
|
||||||
|
## 测试 |
||||||
|
|
||||||
|
```bash |
||||||
|
cd /root/.openclaw/workspace/skills/chinese-almanac |
||||||
|
node almanac.js |
||||||
|
``` |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
{ |
||||||
|
"name": "chinese-almanac", |
||||||
|
"version": "1.0.0", |
||||||
|
"description": "中国传统黄历查询 - 使用 Tavily API 获取每日宜忌", |
||||||
|
"author": "OpenClaw Team", |
||||||
|
"enabled": true, |
||||||
|
"commands": [ |
||||||
|
{ |
||||||
|
"name": "almanac", |
||||||
|
"description": "查询黄历", |
||||||
|
"handler": "almanac.queryAlmanac", |
||||||
|
"usage": "/almanac [日期 YYYY-MM-DD]", |
||||||
|
"examples": [ |
||||||
|
"/almanac", |
||||||
|
"/almanac 2026-02-24", |
||||||
|
"明天黄历", |
||||||
|
"查询 2 月 24 日宜忌" |
||||||
|
] |
||||||
|
} |
||||||
|
], |
||||||
|
"config": { |
||||||
|
"tavily_api_key": "${TAVILY_API_KEY}", |
||||||
|
"default_search_depth": "basic", |
||||||
|
"max_results": 5 |
||||||
|
}, |
||||||
|
"dependencies": [] |
||||||
|
} |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
/** |
||||||
|
* Google Calendar Node.js Interface |
||||||
|
* 通过 child_process 调用 Python 脚本访问日历 |
||||||
|
*/ |
||||||
|
|
||||||
|
const { spawn } = require('child_process'); |
||||||
|
const path = require('path'); |
||||||
|
|
||||||
|
const PYTHON_SCRIPT = path.join(__dirname, '..', 'google-calendar', 'google_calendar.py'); |
||||||
|
const CREDENTIALS_PATH = '/root/.openclaw/credentials/google-calendar-life.json'; |
||||||
|
|
||||||
|
/** |
||||||
|
* 调用 Python Google Calendar 脚本 |
||||||
|
* @param {string} command - 日历命令 (today, tomorrow, week, status) |
||||||
|
* @returns {Promise<string>} 日历信息 |
||||||
|
*/ |
||||||
|
async function getCalendarInfo(command = 'today') { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
const pythonProcess = spawn('python3', [PYTHON_SCRIPT, command], { |
||||||
|
env: { |
||||||
|
...process.env, |
||||||
|
PYTHONPATH: path.join(__dirname, '..', 'google-calendar') |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
let output = ''; |
||||||
|
let errorOutput = ''; |
||||||
|
|
||||||
|
pythonProcess.stdout.on('data', (data) => { |
||||||
|
output += data.toString(); |
||||||
|
}); |
||||||
|
|
||||||
|
pythonProcess.stderr.on('data', (data) => { |
||||||
|
errorOutput += data.toString(); |
||||||
|
}); |
||||||
|
|
||||||
|
pythonProcess.on('close', (code) => { |
||||||
|
if (code === 0) { |
||||||
|
resolve(output.trim()); |
||||||
|
} else { |
||||||
|
reject(new Error(`Python script exited with code ${code}: ${errorOutput}`)); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
pythonProcess.on('error', (err) => { |
||||||
|
reject(err); |
||||||
|
}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 测试日历连接 |
||||||
|
*/ |
||||||
|
async function testCalendarConnection() { |
||||||
|
try { |
||||||
|
const result = await getCalendarInfo('status'); |
||||||
|
return { |
||||||
|
connected: result.includes('✅'), |
||||||
|
message: result |
||||||
|
}; |
||||||
|
} catch (error) { |
||||||
|
return { |
||||||
|
connected: false, |
||||||
|
message: `❌ 连接失败:${error.message}` |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 命令行测试
|
||||||
|
if (require.main === module) { |
||||||
|
const command = process.argv[2] || 'today'; |
||||||
|
getCalendarInfo(command) |
||||||
|
.then(result => console.log(result)) |
||||||
|
.catch(err => console.error('Error:', err.message)); |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = { getCalendarInfo, testCalendarConnection }; |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
{ |
||||||
|
"name": "google-calendar-node", |
||||||
|
"version": "1.0.0", |
||||||
|
"description": "Google Calendar Node.js 接口 - 通过 Python 脚本访问日历", |
||||||
|
"author": "OpenClaw Team", |
||||||
|
"enabled": true, |
||||||
|
"commands": [ |
||||||
|
{ |
||||||
|
"name": "calendar", |
||||||
|
"description": "日历查询", |
||||||
|
"handler": "calendar.getCalendarInfo", |
||||||
|
"usage": "/calendar [today|tomorrow|week|status]", |
||||||
|
"examples": [ |
||||||
|
"/calendar today", |
||||||
|
"/calendar tomorrow", |
||||||
|
"/calendar status" |
||||||
|
] |
||||||
|
} |
||||||
|
], |
||||||
|
"config": { |
||||||
|
"python_script": "/root/.openclaw/workspace/skills/google-calendar/google_calendar.py", |
||||||
|
"credentials_path": "/root/.openclaw/credentials/google-calendar-life.json", |
||||||
|
"timezone": "Asia/Shanghai" |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue