From 6dd29eaee3c2c1b8a0e5bc80e4c74ed1555bb11e Mon Sep 17 00:00:00 2001 From: sansan <77180927+sansan0@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:26:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20StorageManager=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E8=AE=B0=E5=BD=95=E4=BB=A3=E7=90=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20+=20S3=20=E5=88=87=E6=8D=A2=E8=87=B3=20virtual-host?= =?UTF-8?q?ed=20style=20=E6=8F=90=E5=8D=87=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-EN.md | 80 +++++++--------------------------- README.md | 82 +++++++---------------------------- trendradar/__init__.py | 2 +- trendradar/storage/manager.py | 27 ++++++++++++ trendradar/storage/remote.py | 6 +++ version | 2 +- 6 files changed, 66 insertions(+), 133 deletions(-) diff --git a/README-EN.md b/README-EN.md index 17c8880..a87ca8d 100644 --- a/README-EN.md +++ b/README-EN.md @@ -10,8 +10,7 @@ sansan0%2FTrendRadar | Trendshift -302.AI logo -FlashSpeak logo +FlashSpeak logo [![GitHub Stars](https://img.shields.io/github/stars/sansan0/TrendRadar?style=flat-square&logo=github&color=yellow)](https://github.com/sansan0/TrendRadar/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/sansan0/TrendRadar?style=flat-square&logo=github&color=blue)](https://github.com/sansan0/TrendRadar/network/members) @@ -365,14 +364,10 @@ Transform from "algorithm recommendation captivity" to "actively getting the inf - **Major Version Upgrade**: Upgrading from v1.x to v2.y, recommend deleting existing fork and re-forking to save effort and avoid config conflicts -### 2025/12/13 - v4.0.0 +### 2025/12/17 - v4.0.1 -**🎉 Major Update: Comprehensive Refactoring of Storage and Core Architecture** - -- **Multi-Storage Backend Support**: Introduced a brand new storage module supporting local SQLite and remote cloud storage (S3-compatible protocols, Cloudflare R2 recommended for free tier), adaptable to GitHub Actions, Docker, and local environments. -- **Database Structure Optimization**: Refactored SQLite database table structures to improve data efficiency and query performance. -- **Enhanced Features**: Implemented date format standardization, data retention policies, timezone configuration support, and optimized time display. Fixed remote storage data persistence issues to ensure accurate data merging. -- **Cleanup and Compatibility**: Removed most legacy compatibility code and unified data storage and retrieval methods. +- StorageManager adds push record proxy methods +- S3 client switches to virtual-hosted style for better compatibility (supports Tencent Cloud COS and more services) ### 2025/12/13 - mcp-v1.1.0 @@ -388,6 +383,16 @@ Transform from "algorithm recommendation captivity" to "actively getting the inf 👉 Click to expand: Historical Updates +### 2025/12/13 - v4.0.0 + +**🎉 Major Update: Comprehensive Refactoring of Storage and Core Architecture** + +- **Multi-Storage Backend Support**: Introduced a brand new storage module supporting local SQLite and remote cloud storage (S3-compatible protocols, Cloudflare R2 recommended for free tier), adaptable to GitHub Actions, Docker, and local environments. +- **Database Structure Optimization**: Refactored SQLite database table structures to improve data efficiency and query performance. +- **Enhanced Features**: Implemented date format standardization, data retention policies, timezone configuration support, and optimized time display. Fixed remote storage data persistence issues to ensure accurate data merging. +- **Cleanup and Compatibility**: Removed most legacy compatibility code and unified data storage and retrieval methods. + + ### 2025/12/03 - v3.5.0 **🎉 Core Feature Enhancements** @@ -879,16 +884,6 @@ In GitHub Actions environment, data is stored in **Remote Cloud Storage** (suppo For long-term stable operation, we recommend [Docker Deployment](#6-docker-deployment), with data stored locally and no check-in required—though it does require purchasing a cloud server. -
- -> 🎉 **Now Supported: Multi-Cloud Storage Options** -> -> This project now supports S3-compatible protocols. You can choose: -> - **Cloudflare R2** (Recommended, generous free tier) -> - Other S3-compatible storage services -> -> Simply configure the corresponding `S3_ENDPOINT_URL`, `S3_BUCKET_NAME` and other environment variables to switch. - --- 1. **Fork this project** to your GitHub account @@ -3196,7 +3191,7 @@ Cherry Studio provides GUI config interface, 5-minute quick deployment, complex > 💡 **Tip**: Actually not recommended to ask multiple questions at once. If your chosen AI model cannot even sequentially call as shown below, suggest switching models. -MCP usage effect +MCP usage effect @@ -3522,51 +3517,6 @@ Any client supporting Model Context Protocol can connect to TrendRadar: ## 🪄 Sponsors -### 🤖 302.AI - Enterprise AI Resource Platform - -> **302.AI** is a pay-as-you-go enterprise-level AI resource platform -> Providing the latest and most comprehensive **AI models** and **APIs** on the market, plus various ready-to-use online AI applications - -
- -[![Register & Claim](https://img.shields.io/badge/Register_302.AI-Claim_$1_Credit-8B5CF6?style=for-the-badge&logo=openai&logoColor=white)](https://share.302.ai/mEOUzG) - - 302.AI - -
- - - - - > Tracking so many trending topics daily, writing reports, replying messages making your wrists tired? > > Try「FlashSpeak」AI Voice Input - Speak instead of type, 4x faster ⚡ diff --git a/README.md b/README.md index f27ef90..e368338 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ sansan0%2FTrendRadar | Trendshift -302.AI logo -闪电说 logo +闪电说 logo [![GitHub Stars](https://img.shields.io/github/stars/sansan0/TrendRadar?style=flat-square&logo=github&color=yellow)](https://github.com/sansan0/TrendRadar/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/sansan0/TrendRadar?style=flat-square&logo=github&color=blue)](https://github.com/sansan0/TrendRadar/network/members) @@ -411,15 +410,11 @@ GitHub 一键 Fork 即可使用,无需编程基础。 - **大版本升级**:从 v1.x 升级到 v2.y,建议删除现有 fork 后重新 fork,这样更省力且避免配置冲突 -### 2025/12/13 - v4.0.0 -**🎉 重大更新:全面重构存储和核心架构** +### 2025/12/17 - v4.0.1 -- **多存储后端支持**:引入全新的存储模块,支持本地 SQLite 和远程云存储(S3 兼容协议,推荐免费的 Cloudflare R2),适应 GitHub Actions、Docker 和本地环境。 -- **数据库结构优化**:重构 SQLite 数据库表结构,提升数据效率和查询能力。 -- **核心代码模块化**:将主程序逻辑拆分为 trendradar 包的多个模块,显著提升代码可维护性。 -- **增强功能**:实现日期格式标准化、数据保留策略、时区配置支持、时间显示优化,并修复远程存储数据持久化问题,确保数据合并的准确性。 -- **清理和兼容**:移除了大部分历史兼容代码,统一了数据存储和读取方式。 +- StorageManager 添加推送记录代理方法 +- S3 客户端切换至 virtual-hosted style 以提升兼容性(支持腾讯云 COS 等更多服务) ### 2025/12/13 - mcp-v1.1.0 @@ -436,6 +431,17 @@ GitHub 一键 Fork 即可使用,无需编程基础。 👉 点击展开:历史更新 +### 2025/12/13 - v4.0.0 + +**🎉 重大更新:全面重构存储和核心架构** + +- **多存储后端支持**:引入全新的存储模块,支持本地 SQLite 和远程云存储(S3 兼容协议,推荐免费的 Cloudflare R2),适应 GitHub Actions、Docker 和本地环境。 +- **数据库结构优化**:重构 SQLite 数据库表结构,提升数据效率和查询能力。 +- **核心代码模块化**:将主程序逻辑拆分为 trendradar 包的多个模块,显著提升代码可维护性。 +- **增强功能**:实现日期格式标准化、数据保留策略、时区配置支持、时间显示优化,并修复远程存储数据持久化问题,确保数据合并的准确性。 +- **清理和兼容**:移除了大部分历史兼容代码,统一了数据存储和读取方式。 + + ### 2025/12/03 - v3.5.0 **🎉 核心功能增强** @@ -917,16 +923,6 @@ GitHub Actions 环境下,数据存储在 **远程云存储**(支持 S3 兼 如需长期稳定运行,建议使用 [Docker 部署](#6-docker-部署),数据存储在本地,无需签到,不过需要额外付费购买云服务器。 -
- -> 🎉 **已支持:多云存储方案** -> -> 本项目现已支持 S3 兼容协议,你可以选择: -> - **Cloudflare R2**(推荐,免费额度充足) -> - 其他 S3 兼容存储服务 -> -> 只需配置对应的 `S3_ENDPOINT_URL`、`S3_BUCKET_NAME` 等环境变量即可切换。 - --- 1. **Fork 本项目**到你的 GitHub 账户 @@ -3135,7 +3131,7 @@ Cherry Studio 提供 GUI 配置界面,5 分钟快速部署,复杂的部分 > 💡 **提示**:实际不建议一次性问多个问题。如果你选择的 AI 模型连下图的按顺序调用都无法做到,建议换一个。 -mcp 使用效果图 +mcp 使用效果图 @@ -3541,52 +3537,6 @@ MCP Inspector 是官方调试工具,用于测试 MCP 连接: ## 🪄 赞助商 -> **302.AI** 是按用量付费的企业级 AI 资源平台 -> 提供市场上最新、最全面的 **AI 模型**和 **API**,以及多种开箱即用的在线 AI 应用 - -
- -[![注册领取](https://img.shields.io/badge/注册_302.AI-领取_1_美元免费测试额度-8B5CF6?style=for-the-badge&logo=openai&logoColor=white)](https://share.302.ai/mEOUzG) - - 302.AI - -
- - - - - > 每天追踪这么多热点,写报告、回复消息是否让手腕疲惫? > 试试「闪电说」AI 语音输入法 —— 用说的,比打字快 4 倍 ⚡ 。从看热点到输出内容,让效率翻倍 👇 diff --git a/trendradar/__init__.py b/trendradar/__init__.py index 3135177..ab0162f 100644 --- a/trendradar/__init__.py +++ b/trendradar/__init__.py @@ -9,5 +9,5 @@ TrendRadar - 热点新闻聚合与分析工具 from trendradar.context import AppContext -__version__ = "4.0.0" +__version__ = "4.0.1" __all__ = ["AppContext", "__version__"] diff --git a/trendradar/storage/manager.py b/trendradar/storage/manager.py index c488655..eae15c1 100644 --- a/trendradar/storage/manager.py +++ b/trendradar/storage/manager.py @@ -264,6 +264,33 @@ class StorageManager: """是否支持 TXT 快照""" return self.get_backend().supports_txt + # === 推送记录相关方法 === + + def has_pushed_today(self, date: Optional[str] = None) -> bool: + """ + 检查指定日期是否已推送过 + + Args: + date: 日期字符串(YYYY-MM-DD),默认为今天 + + Returns: + 是否已推送 + """ + return self.get_backend().has_pushed_today(date) + + def record_push(self, report_type: str, date: Optional[str] = None) -> bool: + """ + 记录推送 + + Args: + report_type: 报告类型 + date: 日期字符串(YYYY-MM-DD),默认为今天 + + Returns: + 是否记录成功 + """ + return self.get_backend().record_push(report_type, date) + def get_storage_manager( backend_type: str = "auto", diff --git a/trendradar/storage/remote.py b/trendradar/storage/remote.py index e3486d0..a9b071d 100644 --- a/trendradar/storage/remote.py +++ b/trendradar/storage/remote.py @@ -21,11 +21,13 @@ from typing import Dict, List, Optional, Any try: import boto3 + from botocore.config import Config as BotoConfig from botocore.exceptions import ClientError HAS_BOTO3 = True except ImportError: HAS_BOTO3 = False boto3 = None + BotoConfig = None ClientError = Exception from trendradar.storage.base import StorageBackend, NewsItem, NewsData @@ -90,10 +92,14 @@ class RemoteStorageBackend(StorageBackend): self.temp_dir.mkdir(parents=True, exist_ok=True) # 初始化 S3 客户端 + # 使用 virtual-hosted style addressing(主流) + s3_config = BotoConfig(s3={"addressing_style": "virtual"}) + client_kwargs = { "endpoint_url": endpoint_url, "aws_access_key_id": access_key_id, "aws_secret_access_key": secret_access_key, + "config": s3_config, } if region: client_kwargs["region_name"] = region diff --git a/version b/version index 0c89fc9..cc868b6 100644 --- a/version +++ b/version @@ -1 +1 @@ -4.0.0 \ No newline at end of file +4.0.1 \ No newline at end of file