From e8e25274e525d924ce2faa9116f0664a48e978c7 Mon Sep 17 00:00:00 2001 From: zlei9 Date: Sun, 29 Mar 2026 13:07:16 +0800 Subject: [PATCH] Initial commit with translated description --- SKILL.md | 28 ++++++++++++++++++++++++++++ _meta.json | 6 ++++++ scripts/search.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 SKILL.md create mode 100644 _meta.json create mode 100644 scripts/search.py diff --git a/SKILL.md b/SKILL.md new file mode 100644 index 0000000..9266b66 --- /dev/null +++ b/SKILL.md @@ -0,0 +1,28 @@ +--- +name: google-search +description: "使用Google自定义搜索引擎进行网络搜索。" +--- + +# Google Search Skill + +This skill allows OpenClaw agents to perform web searches via Google's Custom Search API (PSE). + +## Setup + +1. **Google Cloud Console:** Create a project and enable the "Custom Search API". +2. **API Key:** Generate an API Key. +3. **Search Engine ID (CX):** Create a Programmable Search Engine at [cse.google.com](https://cse.google.com/cse/all), and get your CX ID. +4. **Environment:** Store your credentials in a `.env` file in your workspace: + ``` + GOOGLE_API_KEY=your_key_here + GOOGLE_CSE_ID=your_cx_id_here + ``` + +## Workflow +... (rest of file) + +## Example Usage + +```bash +GOOGLE_API_KEY=xxx GOOGLE_CSE_ID=yyy python3 skills/google-search/scripts/search.py "OpenClaw documentation" +``` diff --git a/_meta.json b/_meta.json new file mode 100644 index 0000000..53f3fe8 --- /dev/null +++ b/_meta.json @@ -0,0 +1,6 @@ +{ + "ownerId": "kn7ey18zr9mrrcpfc4zwy1brzd80bwjm", + "slug": "google-search", + "version": "1.0.0", + "publishedAt": 1769909754813 +} \ No newline at end of file diff --git a/scripts/search.py b/scripts/search.py new file mode 100644 index 0000000..021b6eb --- /dev/null +++ b/scripts/search.py @@ -0,0 +1,39 @@ +import sys +import json +import requests +import os + +def google_search(query, api_key, cse_id, num_results=5): + url = "https://www.googleapis.com/customsearch/v1" + params = { + 'q': query, + 'key': api_key, + 'cx': cse_id, + 'num': num_results + } + response = requests.get(url, params=params) + response.raise_for_status() + return response.json() + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python google_search.py [num_results]") + sys.exit(1) + + query = sys.argv[1] + num_results = int(sys.argv[2]) if len(sys.argv) > 2 else 5 + + # We will pass these via env vars for security + api_key = os.getenv("GOOGLE_API_KEY") + cse_id = os.getenv("GOOGLE_CSE_ID") + + if not api_key or not cse_id: + print("Error: GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment.") + sys.exit(1) + + try: + results = google_search(query, api_key, cse_id, num_results) + print(json.dumps(results, indent=2)) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1)