Skill: qq853632587/weibo-hot-daily (version 2.1.1)

--- name: weibo-hot-daily description: "🔥 每日自动抓取微博热搜榜，支持AI摘要和多渠道推送。自媒体运营必备！免费使用，定制开发请联系作者。" homepage: https://github.com/openclaw/weibo-hot-daily metadata: { "openclaw": { "emoji": "🔥", "requires": { "bins": ["python3"] }, }, } --- # 🔥 微博热搜日报 v2.1 每日自动抓取微博热搜榜，支持AI摘要和多渠道推送。 ## ✨ v2.1 新功能 - ✅ 优化API调用稳定性 - ✅ 改善数据展示格式 ## 📦 安装 ```bash npx clawhub@latest install weibo-hot-daily ``` ## 🚀 使用 ```bash python3 fetch_hot.py --top 10 python3 fetch_hot.py --top 50 --summary --output hot.json ``` ## 💰 定制服务 **免费使用本技能，如需以下服务请联系作者：** - 🔧 定制开发：微博数据监控方案 - 📊 舆情分析：品牌/话题监控 - 🤖 自动化部署：完整监控系统 **联系方式：** - 📱 QQ：2595075878 - 📧 邮箱：[REDACTED_SECRET] ## ⚖️ 免责声明 本技能所获取的数据来自微博公开API，仅用于个人学习和技术研究目的。 - 📌 **数据来源**：微博公开API接口 - 📌 **非商业性质**：本技能为开源免费工具，不涉及任何商业引导 - 📌 **版权说明**：所有数据内容的版权归新浪微博所有 - 📌 **使用限制**：请遵守微博用户协议，禁止用于非法用途 - 📌 **免责条款**：本技能按"现状"提供，使用者需自行承担使用风险 ## 📄 许可证 MIT License

path: fetch_hot.py
content: #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
微博热搜日报 v2.0 - 自动抓取微博热搜榜
作者: 小天🦞
版本: 2.0.0
"""

import argparse
import json
import csv
import sys
import os
import urllib.request
import urllib.error
from datetime import datetime
from typing import List, Dict, Optional

# 设置控制台编码
if sys.platform == 'win32':
    os.system('chcp 65001 >nul 2>&1')
    sys.stdout.reconfigure(encoding='utf-8')
    sys.stderr.reconfigure(encoding='utf-8')

# 微博热搜API地址
WEIBO_HOT_API = "https://weibo.com/ajax/side/hotSearch"

# 分类名称映射
CATEGORY_MAP = {
    'all': '全部',
    'entertainment': '娱乐',
    'sports': '体育',
    'tech': '科技',
    'society': '社会',
    'finance': '财经',
    'international': '国际'
}


class WeiboHotFetcher:
    """微博热搜抓取器"""

    def __init__(self):
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
            'Referer': 'https://weibo.com/',
            'Accept': 'application/json, text/plain, */*',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
            'Cookie': [REDACTED_SECRET]
        }

    def fetch_hot(self, top: int = 50, category: str = 'all') -> List[Dict]:
        """获取热搜榜"""
        url = WEIBO_HOT_API

        try:
            req = urllib.request.Request(url, headers=self.headers)
            with urllib.request.urlopen(req, timeout=10) as response:
                data = json.loads(response.read().decode('utf-8'))

            if data.get('ok') != 1:
                print(f"[ERROR] API错误: {data.get('msg', '未知错误')}", file=sys.stderr)
                return []

            realtime = data.get('data', {}).get('realtime', [])
            return [self._parse_topic(t, i+1) for i, t in enumerate(realtime[:top])]

        except urllib.error.URLError as e:
            print(f"[ERROR] 网络错误: {e}", file=sys.stderr)
            return []
        except Exception as e:
            print(f"[ERROR] 未知错误: {e}", file=sys.stderr)
            return []

    def _parse_topic(self, topic: Dict, rank: int) -> Dict:
        """解析热搜数据"""
        return {
            'rank': rank,
            'title': topic.get('word', ''),
            'hot_value': topic.get('num', 0),
            'category': topic.get('category', '其他'),
            'label_name': topic.get('label_name', ''),
            'url': f"https://s.weibo.com/weibo?q={urllib.request.quote(topic.get('word', ''))}"
        }


def format_number(num: int) -> str:
    """格式化数字（万/亿）"""
    if num >= 100000000:
        return f"{num/100000000:.1f}亿"
    if num >= 10000:
        return f"{num/10000:.1f}万"
    return str(num)


def generate_summary(topics: List[Dict], [REDACTED_SECRET] = None) -> str:
    """生成AI摘要"""
    if not api_key:
        # 简单摘要（不需要API）
        categories = {}
        total_hot = 0

        for t in topics:
            cat = t.get('category', '其他')
            categories[cat] = categories.get(cat, 0) + 1
            total_hot += t.get('hot_value', 0)

        top_cats = sorted(categories.items(), key=lambda x: x[1], reverse=True)[:3]
        cat_str = "、".join([c[0] for c in top_cats])

        return (
            f"[SUMMARY] 今日热搜摘要\n"
            f"共 {len(topics)} 个热搜话题，"
            f"总热度 {format_number(total_hot)}\n"
            f"热门分类：{cat_str}\n"
            f"Top 1：{topics[0]['title']}（热度 {format_number(topics[0]['hot_value'])}）"
        )

    # TODO: 调用OpenAI API生成更详细的摘要
    return "AI摘要功能需要配置OpenAI API Key"


def output_json(topics: List[Dict], output_file: str, summary: str = ""):
    """输出JSON格式"""
    result = {
        'date': datetime.now().strftime('%Y-%m-%d'),
        'total': len(topics),
        'summary': summary,
        'topics': topics
    }

    with open(output_file, 'w', encoding='utf-8') as f:
        json.dump(result, f, ensure_ascii=False, indent=2)

    print(f"[OK] 已保存到 {output_file}")


def output_csv(topics: List[Dict], output_file: str):
    """输出CSV格式"""
    if not topics:
        print("[ERROR] 没有数据可导出")
        return

    fieldnames = ['rank', 'title', 'hot_value', 'category', 'label_name', 'url']

    with open(output_file, 'w', encoding='utf-8-sig', newline='') as f:
        writer = csv.DictWriter(f, fieldnames=fieldnames)
        writer.writeheader()
        for t in topics:
            writer.writerow({k: t.get(k, '') for k in fieldnames})

    print(f"[OK] 已保存到 {output_file}")


def print_table(topics: List[Dict]):
    """打印表格到终端"""
    if not topics:
        print("[ERROR] 没有数据")
        return

    print("\n" + "="*80)
    print(f"[HOT] 微博热搜榜 - {datetime.now().strftime('%Y-%m-%d %H:%M')}")
    print("="*80)

    for t in topics:
        print(f"\n#{t['rank']} {t['title']}")
        print(f"   [HOT] {format_number(t['hot_value'])} | [CAT] {t.get('category', '其他')}")
        if t.get('label_name'):
            print(f"   [LABEL] {t['label_name']}")
        print(f"   [LINK] {t['url']}")

    print("\n" + "="*80)


def main():
    parser = argparse.ArgumentParser(description='[HOT] 微博热搜日报 - 抓取微博热搜榜')
    parser.add_argument('--top', type=int, default=50, help='获取话题数量 (默认: 50)')
    parser.add_argument('--category', type=str, default='all', help='分类筛选 (entertainment/sports/tech/society/finance/international)')
    parser.add_argument('--summary', action='store_true', help='生成摘要')
    parser.add_argument('--api-key', type=str, help='OpenAI API Key')
    parser.add_argument('--output', type=str, help='输出文件路径')
    parser.add_argument('--format', choices=['json', 'csv'], default='json', help='输出格式')
    parser.add_argument('--quiet', action='store_true', help='静默模式')

    args = parser.parse_args()

    # 抓取数据
    fetcher = WeiboHotFetcher()
    topics = fetcher.fetch_hot(top=args.top, category=args.category)

    if not topics:
        print("[ERROR] 未获取到数据")
        sys.exit(1)

    # 生成摘要
    summary = ""
    if args.summary:
        summary = generate_summary(topics, args.api_key)

    # 输出
    if not args.quiet:
        print_table(topics)
        if summary:
            print(f"\n[SUMMARY] 摘要：\n{summary}")

    # 保存文件
    if args.output:
        if args.format == 'csv':
            output_csv(topics, args.output)
        else:
            output_json(topics, args.output, summary)

    return topics


if __name__ == '__main__':
    main()


path: package.json
content: {
  "name": "weibo-hot-daily",
  "version": "1.0.0",
  "description": "🔥 每日自动抓取微博热搜榜，支持AI摘要和多渠道推送",
  "author": "小天🦞",
  "license": "MIT",
  "keywords": [
    "weibo",
    "hot",
    "trending",
    "热搜",
    "微博",
    "daily",
    "report"
  ],
  "main": "fetch_hot.py",
  "scripts": {
    "start": "python3 fetch_hot.py",
    "top10": "python3 fetch_hot.py --top 10",
    "top50": "python3 fetch_hot.py --top 50",
    "export": "python3 fetch_hot.py --top 50 --output hot_topics.json"
  },
  "dependencies": {
    "python": ">=3.7"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/openclaw/weibo-hot-daily"
  },
  "pricing": {
    "free": {
      "description": "免费版 - Top 10 基础数据",
      "features": ["每日Top 10", "基础数据展示"]
    },
    "pro": {
      "price": 49,
      "currency": "CNY",
      "description": "Pro版 - 全部功能",
      "features": ["Top 50", "AI摘要", "多渠道推送", "定时任务", "CSV导出"]
    }
  }
}


path: README.md
content: # 🔥 微博热搜日报 - Weibo Hot Daily

> 自动抓取微博热搜榜，支持AI摘要和多渠道推送

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![ClawHub](https://img.shields.io/badge/ClawHub-Available-brightgreen)](https://clawhub.ai)

## ✨ 功能特性

- 📊 自动抓取微博热搜榜 Top 50
- 🤖 AI 智能分类摘要
- 📱 多渠道推送（Telegram/微信/邮件）
- ⏰ 定时执行（每日自动更新）
- 📈 数据统计（热度值/排名变化）

## 🚀 快速开始

### 安装

```bash
npx clawhub@latest install weibo-hot-daily
```

### 使用

```bash
# 获取今日热搜 Top 10
python3 fetch_hot.py --top 10

# 获取完整 Top 50
python3 fetch_hot.py --top 50

# 生成摘要并导出
python3 fetch_hot.py --summary --output hot.json
```

## 📊 输出示例

```
#1 太原火灾已致1死25伤
   [HOT] 118.2万 | [CAT] 社会
   [LINK] https://s.weibo.com/weibo?q=...
```

## 💰 定价

- **免费版**：每日 Top 10，基础数据
- **Pro版（49元）**：Top 50 + AI摘要 + 多渠道推送

## 📄 许可证

MIT License - 小天🦞


path: _meta.json
content: ownerId: kn7dhwrh3611jhh9nac60jx2jx82h264
slug: weibo-hot-daily
version: 2.1.0
publishedAt: 1774720444459

Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)