改成了每小时执行抖音播放量抓取
This commit is contained in:
parent
bd58c1dc8f
commit
fe6c867579
@ -264,14 +264,11 @@ class DouyinAutoScheduler:
|
||||
logging.error(f"详细错误信息: {traceback.format_exc()}")
|
||||
|
||||
|
||||
|
||||
def setup_schedule(self):
|
||||
"""设置定时任务"""
|
||||
# 从配置文件读取执行时间
|
||||
scheduler_time = config.SCHEDULER_TIME
|
||||
schedule.every().day.at(scheduler_time).do(self.run_douyin_scraper)
|
||||
|
||||
logging.info(f"⏰ 定时器已设置:每晚{scheduler_time}执行抖音播放量抓取")
|
||||
# 每小时执行一次抖音播放量抓取
|
||||
schedule.every().hour.do(self.run_douyin_scraper)
|
||||
logging.info(f"⏰ 定时器已设置:每小时执行抖音播放量抓取")
|
||||
|
||||
def show_next_run(self):
|
||||
"""显示下次执行时间"""
|
||||
@ -299,7 +296,7 @@ class DouyinAutoScheduler:
|
||||
"""启动定时器"""
|
||||
self.is_running = True
|
||||
logging.info("🚀 抖音播放量自动抓取定时器已启动")
|
||||
logging.info(f"⏰ 执行时间:每天{config.SCHEDULER_TIME}执行抖音播放量抓取")
|
||||
logging.info(f"⏰ 执行时间:每小时执行抖音播放量抓取")
|
||||
logging.info("📁 目标脚本:rank_data_scraper.py")
|
||||
logging.info("💾 数据保存:MongoDB")
|
||||
logging.info("⏹️ 按 Ctrl+C 停止定时器")
|
||||
|
||||
@ -2,9 +2,10 @@ import os
|
||||
import importlib
|
||||
|
||||
# 数据库配置
|
||||
MONGO_URI = "mongodb://localhost:27017"
|
||||
# MONGO_URI = "mongodb://mongouser:Jdei2243afN@172.16.0.6:27017,172.16.0.4:27017/test?replicaSet=cmgo-r6qkaern_0&authSource=admin"
|
||||
MONGO_DB_NAME = "Rankings"
|
||||
# MONGO_URI = "mongodb://localhost:27017"
|
||||
# MONGO_DB_NAME = "jubian"
|
||||
MONGO_URI = "mongodb://mongouser:Jdei2243afN@172.16.0.6:27017,172.16.0.4:27017/test?replicaSet=cmgo-r6qkaern_0&authSource=admin"
|
||||
MONGO_DB_NAME = "kemeng_media"
|
||||
|
||||
# 应用配置
|
||||
APP_ENV = os.getenv('APP_ENV', 'development')
|
||||
|
||||
267
docs/API接口文档.md
267
docs/API接口文档.md
@ -85,12 +85,17 @@ GET /
|
||||
"version": "2.0",
|
||||
"description": "主程序服务 - 整合小程序API功能",
|
||||
"endpoints": {
|
||||
"/api/videos": "获取视频列表 (支持分页和排序)",
|
||||
"/api/top": "获取热门视频榜单",
|
||||
"/api/search": "搜索视频",
|
||||
"/api/detail": "获取视频详情",
|
||||
"/api/stats": "获取统计信息",
|
||||
"/api/health": "健康检查"
|
||||
"/api/rank/videos": "获取视频列表 (支持分页和排序)",
|
||||
"/api/rank/top": "获取热门视频榜单",
|
||||
"/api/rank/search": "搜索视频",
|
||||
"/api/rank/detail": "获取视频详情",
|
||||
"/api/rank/stats": "获取统计信息",
|
||||
"/api/rank/health": "健康检查",
|
||||
"/api/rank/rankings": "获取榜单列表",
|
||||
"/api/rank/rankings/dates": "获取可用榜单日期",
|
||||
"/api/rank/rankings/types": "获取榜单类型",
|
||||
"/api/rank/rankings/latest": "获取最新榜单",
|
||||
"/api/rank/rankings/stats": "获取榜单统计"
|
||||
},
|
||||
"features": [
|
||||
"分页支持",
|
||||
@ -98,6 +103,8 @@ GET /
|
||||
"搜索功能",
|
||||
"详情查看",
|
||||
"统计分析",
|
||||
"榜单查询",
|
||||
"动态排序",
|
||||
"小程序优化"
|
||||
]
|
||||
}
|
||||
@ -108,7 +115,7 @@ GET /
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/videos
|
||||
GET /api/rank/videos
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -126,13 +133,13 @@ GET /api/videos
|
||||
**使用示例**
|
||||
```
|
||||
# 按播放量排序
|
||||
GET /api/videos?page=1&limit=20&sort=playcount
|
||||
GET /api/rank/videos?page=1&limit=20&sort=playcount
|
||||
|
||||
# 按增长量排序(默认昨天到今天的增长)
|
||||
GET /api/videos?page=1&limit=20&sort=growth
|
||||
GET /api/rank/videos?page=1&limit=20&sort=growth
|
||||
|
||||
# 按自定义日期范围的增长排序
|
||||
GET /api/videos?page=1&limit=20&sort=growth&start_date=2025-10-16&end_date=2025-10-17
|
||||
GET /api/rank/videos?page=1&limit=20&sort=growth&start_date=2025-10-16&end_date=2025-10-17
|
||||
```
|
||||
|
||||
**响应示例**
|
||||
@ -170,7 +177,7 @@ GET /api/videos?page=1&limit=20&sort=growth&start_date=2025-10-16&end_date=2025-
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/top
|
||||
GET /api/rank/top
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -183,7 +190,7 @@ GET /api/top
|
||||
|
||||
**使用示例**
|
||||
```
|
||||
GET /api/top?limit=10
|
||||
GET /api/rank/top?limit=10
|
||||
```
|
||||
|
||||
**响应示例**
|
||||
@ -213,7 +220,7 @@ GET /api/top?limit=10
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/search
|
||||
GET /api/rank/search
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -228,7 +235,7 @@ GET /api/search
|
||||
|
||||
**使用示例**
|
||||
```
|
||||
GET /api/search?q=关键词&page=1&limit=10
|
||||
GET /api/rank/search?q=关键词&page=1&limit=10
|
||||
```
|
||||
|
||||
**响应示例**
|
||||
@ -266,7 +273,7 @@ GET /api/search?q=关键词&page=1&limit=10
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/detail
|
||||
GET /api/rank/detail
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -279,7 +286,7 @@ GET /api/detail
|
||||
|
||||
**使用示例**
|
||||
```
|
||||
GET /api/detail?id=674f1234567890abcdef
|
||||
GET /api/rank/detail?id=674f1234567890abcdef
|
||||
```
|
||||
|
||||
**响应示例**
|
||||
@ -306,7 +313,7 @@ GET /api/detail?id=674f1234567890abcdef
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/stats
|
||||
GET /api/rank/stats
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -360,7 +367,7 @@ GET /api/stats
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/health
|
||||
GET /api/rank/health
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
@ -382,6 +389,222 @@ GET /api/health
|
||||
}
|
||||
```
|
||||
|
||||
### 8. 获取榜单列表
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/rank/rankings
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
获取榜单列表,支持按日期和类型查询,支持动态排序
|
||||
|
||||
**请求参数**
|
||||
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|
||||
|--------|------|------|--------|------|
|
||||
| date | string | 否 | 最新日期 | 日期,格式:YYYY-MM-DD |
|
||||
| type | string | 否 | - | 榜单类型:playcount(播放量榜) / growth(增长榜) / newcomer(新晋榜) |
|
||||
| sort_by | string | 否 | default | 排序方式:default / play_vv_change / play_vv_change_rate / play_vv |
|
||||
| sort_order | string | 否 | desc | 排序顺序:asc / desc |
|
||||
| page | int | 否 | 1 | 页码 |
|
||||
| limit | int | 否 | 50 | 每页数量 |
|
||||
|
||||
**使用示例**
|
||||
```
|
||||
# 获取最新日期的所有榜单
|
||||
GET /api/rank/rankings
|
||||
|
||||
# 获取指定日期的播放量榜
|
||||
GET /api/rank/rankings?date=2025-01-17&type=playcount
|
||||
|
||||
# 按播放量变化排序
|
||||
GET /api/rank/rankings?sort_by=play_vv_change&sort_order=desc
|
||||
|
||||
# 分页获取增长榜
|
||||
GET /api/rank/rankings?type=growth&page=1&limit=20
|
||||
```
|
||||
|
||||
**响应示例**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "获取榜单成功",
|
||||
"data": {
|
||||
"rankings": [
|
||||
{
|
||||
"date": "2025-01-17",
|
||||
"ranking_type": "playcount",
|
||||
"ranking_name": "播放量榜",
|
||||
"description": "按播放量排序的榜单",
|
||||
"data": [
|
||||
{
|
||||
"_id": "674f1234567890abcdef",
|
||||
"mix_name": "热门合集1",
|
||||
"play_vv": 120000000,
|
||||
"rank": 1,
|
||||
"timeline_data": {
|
||||
"play_vv_change": 5000000,
|
||||
"play_vv_change_rate": 4.35
|
||||
}
|
||||
}
|
||||
],
|
||||
"total_count": 100,
|
||||
"current_page_count": 20,
|
||||
"generated_at": "2025-01-17 15:30:00",
|
||||
"version": "1.0",
|
||||
"sort_info": {
|
||||
"sort_by": "default",
|
||||
"sort_order": "desc"
|
||||
}
|
||||
}
|
||||
],
|
||||
"total": 1,
|
||||
"page": 1,
|
||||
"limit": 50,
|
||||
"sort_by": "default",
|
||||
"sort_order": "desc"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 9. 获取可用榜单日期
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/rank/rankings/dates
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
获取所有可用的榜单日期列表
|
||||
|
||||
**请求参数**
|
||||
无
|
||||
|
||||
**响应示例**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "获取日期列表成功",
|
||||
"data": {
|
||||
"dates": [
|
||||
"2025-01-17",
|
||||
"2025-01-16",
|
||||
"2025-01-15"
|
||||
],
|
||||
"total": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 10. 获取榜单类型
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/rank/rankings/types
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
获取支持的榜单类型及其说明
|
||||
|
||||
**请求参数**
|
||||
无
|
||||
|
||||
**响应示例**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "获取榜单类型成功",
|
||||
"data": {
|
||||
"types": [
|
||||
{
|
||||
"type": "playcount",
|
||||
"description": "播放量榜 - 按播放量排序"
|
||||
},
|
||||
{
|
||||
"type": "growth",
|
||||
"description": "增长榜 - 播放量增长最快"
|
||||
},
|
||||
{
|
||||
"type": "newcomer",
|
||||
"description": "新晋榜 - 新上榜内容"
|
||||
}
|
||||
],
|
||||
"total": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 11. 获取最新榜单
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/rank/rankings/latest
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
获取最新日期的所有类型榜单(每个榜单只返回前20条数据)
|
||||
|
||||
**请求参数**
|
||||
无
|
||||
|
||||
**响应示例**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "获取最新榜单成功",
|
||||
"data": {
|
||||
"date": "2025-01-17",
|
||||
"rankings": [
|
||||
{
|
||||
"ranking_type": "playcount",
|
||||
"ranking_name": "播放量榜",
|
||||
"description": "按播放量排序的榜单",
|
||||
"data": [
|
||||
{
|
||||
"_id": "674f1234567890abcdef",
|
||||
"mix_name": "热门合集1",
|
||||
"play_vv": 120000000,
|
||||
"rank": 1
|
||||
}
|
||||
],
|
||||
"total_count": 100,
|
||||
"preview_count": 20
|
||||
}
|
||||
],
|
||||
"total_types": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 12. 获取榜单统计
|
||||
|
||||
**接口地址**
|
||||
```
|
||||
GET /api/rank/rankings/stats
|
||||
```
|
||||
|
||||
**功能描述**
|
||||
获取榜单系统的统计信息
|
||||
|
||||
**请求参数**
|
||||
无
|
||||
|
||||
**响应示例**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "获取榜单统计成功",
|
||||
"data": {
|
||||
"total_rankings": 150,
|
||||
"total_dates": 30,
|
||||
"total_types": 3,
|
||||
"latest_date": "2025-01-17",
|
||||
"earliest_date": "2024-12-18",
|
||||
"date_range": "2024-12-18 至 2025-01-17"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 通用错误格式
|
||||
@ -406,7 +629,7 @@ GET /api/health
|
||||
```javascript
|
||||
// 小程序端示例
|
||||
wx.request({
|
||||
url: 'http://localhost:5000/api/videos',
|
||||
url: 'http://localhost:5000/api/rank/videos',
|
||||
data: {
|
||||
page: 1,
|
||||
limit: 20,
|
||||
@ -458,5 +681,7 @@ python app.py
|
||||
|
||||
---
|
||||
|
||||
**文档版本**:v2.0
|
||||
**最后更新**:2025-10-17**维护者**:系统自动生成
|
||||
**文档版本**:v3.0
|
||||
**最后更新**:2025-01-17
|
||||
**维护者**:系统自动生成
|
||||
**更新内容**:新增榜单查询相关API接口,更新所有接口路径为/api/rank前缀
|
||||
Loading…
x
Reference in New Issue
Block a user