OpenSenseNova/SenseNova-Skills / skills/sn-search-code
sn-search-code
Verified用于查找代码示例、开源项目、GitHub Issue、技术问答、开发者讨论、HuggingFace 模型/数据集/Space。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.7 KB |
| requirements.txt | manifest | 12 B |
| scripts/github_search.py | script | 3.1 KB |
| scripts/hackernews_search.py | script | 2.8 KB |
| scripts/huggingface_search.py | script | 4.3 KB |
| scripts/search_utils.py | script | 4.3 KB |
| scripts/stackoverflow_search.py | script | 2.7 KB |
scripts/stackoverflow_search.py
View on GitHub#!/usr/bin/env python3
"""Stack Overflow 搜索。通过 Stack Exchange API v2.3。"""
import sys
from search_utils import build_parser, get_client, get_key, make_item, make_result, print_json
API_URL = "https://api.stackexchange.com/2.3/search/advanced"
def search(query: str, limit: int, sort: str = "relevance", tagged: str | None = None, api_key: str | None = None) -> list[dict]:
"""执行 Stack Overflow 搜索。"""
params: dict = {
"q": query,
"order": "desc",
"sort": sort,
"site": "stackoverflow",
"pagesize": min(limit, 100),
"filter": "withbody", # 包含 body 摘要
}
if tagged:
params["tagged"] = tagged
if api_key:
params["key"] = api_key
with get_client() as client:
resp = client.get(API_URL, params=params)
resp.raise_for_status()
data = resp.json()
items = []
for item in data.get("items", [])[:limit]:
body = item.get("body", "")
snippet = _strip_html(body)
items.append(make_item(
title=_unescape(item.get("title", "")),
url=item.get("link", ""),
snippet=snippet,
score=item.get("score", 0),
answer_count=item.get("answer_count", 0),
is_answered=item.get("is_answered", False),
accepted_answer_id=item.get("accepted_answer_id"),
tags=item.get("tags", []),
creation_date=item.get("creation_date"),
))
return items
def _strip_html(html: str) -> str:
"""去除 HTML 标签并反转义实体。"""
import re, html as html_mod
text = re.sub(r"<[^>]+>", " ", html)
text = re.sub(r"\s+", " ", text).strip()
return html_mod.unescape(text)
def _unescape(text: str) -> str:
"""反转义 HTML 实体。"""
import html
return html.unescape(text)
def main():
parser = build_parser("搜索 Stack Overflow 问答")
parser.add_argument("--sort", default="relevance",
choices=["relevance", "votes", "creation", "activity"],
help="排序方式(默认 relevance)")
parser.add_argument("--tagged", help="按标签过滤,多个用分号分隔(如 python;asyncio)")
parser.add_argument("--api-key", help="Stack Exchange API key(可选,提高限额)")
args = parser.parse_args()
api_key = get_key("SO_API_KEY", args.api_key)
try:
items = search(args.query, args.limit, args.sort, args.tagged, api_key)
print_json(make_result(True, args.query, "stackoverflow", items))
except Exception as e:
print_json(make_result(False, args.query, "stackoverflow", [], str(e)))
sys.exit(1)
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |