From a78f9c17fdde28187950017071854301eb9b65d9 Mon Sep 17 00:00:00 2001 From: jowe lin Date: Fri, 3 Apr 2026 21:08:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - generate_ai_news.py: 自动生成并推送每日AI新闻 --- scripts/generate_ai_news.py | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 scripts/generate_ai_news.py diff --git a/scripts/generate_ai_news.py b/scripts/generate_ai_news.py new file mode 100644 index 0000000..af49140 --- /dev/null +++ b/scripts/generate_ai_news.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +""" +AI 每日新闻生成器 +- 搜索最新 AI 产品 +- 生成 HTML 页面 +- 推送到 Gitea 仓库 +""" + +import os +import sys +import json +import subprocess +from datetime import datetime +from pathlib import Path + +# Gitea 配置 +GITEA_URL = "https://git.zjpb.net" +GITEA_USER = "jowelin83" +GITEA_TOKEN = "2882a85f18cdd6fcfcda5a64603dbf5bfa46947d" +REPO_NAME = "ai-daily-news" + +# 临时目录 +TEMP_DIR = Path("/tmp/ai-news-gen") +REPO_DIR = TEMP_DIR / REPO_NAME + +def search_ai_products(): + """搜索最新AI产品(使用 web_search)""" + # 这里需要调用 OpenClaw 的 web_search 工具 + # 现在返回示例数据 + return [ + { + "name": "示例产品", + "category": "AI工具", + "desc": "示例描述", + "company": "Example Inc", + "date": "1天前", + "tags": ["热门", "AI"] + } + ] + +def generate_html(products, date_str): + """生成HTML页面""" + html = f""" + + + + + 🔥 AI每日新闻 - {date_str} + + + + + + +""" + return html + +def push_to_gitea(date_str, html_content): + """推送到Gitea""" + # 克隆仓库 + repo_url = f"https://{GITEA_TOKEN}@{GITEA_URL.replace('https://', '')}/{GITEA_USER}/{REPO_NAME}.git" + + if not REPO_DIR.exists(): + subprocess.run(["git", "clone", repo_url], cwd=TEMP_DIR, check=True) + + # 创建日期目录 + date_dir = REPO_DIR / date_str + date_dir.mkdir(exist_ok=True) + + # 写入HTML + (date_dir / "index.html").write_text(html_content) + + # 提交推送 + subprocess.run(["git", "add", "."], cwd=REPO_DIR, check=True) + subprocess.run(["git", "commit", "-m", f"feat: 添加 {date_str} AI新闻"], cwd=REPO_DIR, check=True) + subprocess.run(["git", "push", "origin", "main"], cwd=REPO_DIR, check=True) + +def main(): + # 获取日期 + today = datetime.now().strftime("%Y-%m-%d") + + # 搜索产品 + products = search_ai_products() + + # 生成HTML + html = generate_html(products, today) + + # 推送到Gitea + push_to_gitea(today, html) + + print(f"✅ {today} AI新闻已推送") + +if __name__ == "__main__": + main()