chore: rename skill.md to SKILL.md, update README, add -o path validation
chore: rename skill.md to SKILL.md, update README, add -o path validation
This commit is contained in:
3 files changed
+27
-3
No files matched your search
@@ -5,8 +5,11 @@ Multi-source web search CLI tool — search across **28 engines** from your term
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Install with uv (recommended)
|
||||
# Option 1: pip install (recommended for CodeBuddy Agent use)
|
||||
cd web-search-skills
|
||||
pip install -e .
|
||||
|
||||
# Option 2: uv tool install (alternative)
|
||||
uv tool install -e .
|
||||
|
||||
# Now use globally from anywhere
|
||||
@@ -20,6 +23,8 @@ Or run directly without install:
|
||||
python ws.py wechat 蒙面财经
|
||||
```
|
||||
|
||||
> Requires Python 3.8+. After `pip install -e .`, the `web-search` command is available globally.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
@@ -46,7 +51,7 @@ web-search <command> <query> [options]
|
||||
|-------------------|----------------------------------------------|
|
||||
| `-n N` | Max results per source (default: 10) |
|
||||
| `-j` | JSON output |
|
||||
| `-o FILE` | Save to JSON file |
|
||||
| `-o FILE` | Save to JSON file (path restricted to current directory) |
|
||||
| `-s NAME [...]` | Specific source(s) — engine names or categories (e.g. `-s "Hacker News" V2EX`, `-s web news`) |
|
||||
| `-r cn/global` | Region filter (web search) |
|
||||
| `--site SITE` | Restrict to site (baidu command only) |
|
||||
|
||||
@@ -158,6 +158,9 @@ web-search health
|
||||
|
||||
## Python API (for programmatic use)
|
||||
|
||||
> **Tip:** For Agent use, prefer invoking the `web-search` CLI command directly (see examples above).
|
||||
> The API import below only works when running from the project root directory.
|
||||
|
||||
```python
|
||||
from scripts.unified_search import UnifiedSearch
|
||||
|
||||
@@ -177,6 +180,16 @@ async def main():
|
||||
|
||||
## Important Notes
|
||||
|
||||
### Installation
|
||||
The `web-search` CLI must be installed first before use:
|
||||
```bash
|
||||
cd web-search-skills
|
||||
pip install -e .
|
||||
```
|
||||
This registers `web-search` as a global command. Requires Python 3.8+.
|
||||
|
||||
### Known Limitations
|
||||
|
||||
- **WeChat** via Sogou has anti-scraping limits, may return empty
|
||||
- **财联社 / 华尔街见闻** need JS rendering → returns search page URL, not parsed results
|
||||
- **Baidu Qianfan** requires `BAIDU_API_KEY` env var
|
||||
+7
-1
@@ -415,7 +415,7 @@ async def _run_search(args):
|
||||
|
||||
_print_results(results, fmt="json" if args.json else "text")
|
||||
|
||||
# Save to file if requested
|
||||
# Save to file if requested (with basic path-sanitization)
|
||||
if args.output:
|
||||
output_data = json.dumps(
|
||||
[{
|
||||
@@ -440,6 +440,12 @@ async def _run_search(args):
|
||||
indent=2,
|
||||
)
|
||||
output_path = os.path.abspath(args.output)
|
||||
# Restrict output to the project root or current working directory
|
||||
allowed_base = os.path.abspath(os.getcwd())
|
||||
if not output_path.startswith(allowed_base):
|
||||
print(f"错误: 输出路径超出允许范围 ({allowed_base})", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
f.write(output_data)
|
||||
print(f"\n结果已保存至: {output_path}")
|
||||
|
||||
Reference in new issue
Block a user