Files
tophux_scrape/.trae/documents/实现用户关注数转换功能.md
2025-12-17 21:34:59 +08:00

69 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 实现计划
### 1. 数据库结构更新
* **修改`init_database`方法**:在`product_analysis`表中添加`follows`字段,用于存储转换后的用户关注数
### 2. 添加用户关注数转换方法
* **创建`convert_user_count_to_number`方法**使用Ollama API将`user_count`文本转换为数字
* 处理不同格式:"53 followers" → 53"1.9K followers" → 1900
* 调用Ollama API进行智能转换
* 返回转换后的数字
### 3. 集成到现有分析流程
* **修改`get_product_data`方法**:在查询中包含`user_count``url`字段
* **更新`analyze_products`方法**
* 扩展返回值处理,包含`user_count``url`
* 在分析过程中调用转换方法处理关注数
* 将转换后的数字传递给保存方法
### 4. 更新数据保存方法
* **修改`save_analysis_result`方法**:添加`follows`参数,将转换后的关注数保存到数据库
### 5. 添加关注数分析更新功能
* **创建`analyze_follower_counts`方法**
* 查询所有产品及其分析记录
* 对每个产品转换`user_count`并更新`product_analysis.follows`
* 处理已有分析记录的关注数更新
### 6. 完善工作流程
* **更新`run_full_workflow_async`方法**添加第4步执行关注数分析更新
## 预期效果
* 新的`product_analysis`表将包含`follows`字段,存储转换后的数字关注数
* 新分析的产品将自动转换并保存关注数
* 已有产品将通过额外步骤更新关注数
* 使用Ollama API确保转换准确性
## 关键技术点
* SQLite数据库表结构修改
* Ollama API调用与结果解析
* 文本到数字的智能转换
* 现有代码的无缝集成
* 批量数据处理与更新