74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
||||
|
|
"""
|
|||
|
|
筛选 TOP 视频 — 已整合到 excel_tool.py select-top6 子命令。
|
|||
|
|
此文件保留向后兼容,实际调用 excel_tool.select_top6()(默认取6条)。
|
|||
|
|
|
|||
|
|
用法:
|
|||
|
|
python select_top6.py <excel路径> [--count 6] [--output output.json]
|
|||
|
|
|
|||
|
|
新用法(推荐):
|
|||
|
|
python excel_tool.py select-top6 <excel路径> [--count 6] [--output output.json]
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import sys
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
# 确保能找到 excel_tool
|
|||
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|||
|
|
from excel_tool import select_top6, HEADERS
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
if len(sys.argv) < 2:
|
|||
|
|
print("用法: python select_top6.py <excel路径> [--count 6] [--output output.json]")
|
|||
|
|
print("推荐: python excel_tool.py select-top6 <excel路径> [--count 6] [--output output.json]")
|
|||
|
|
sys.exit(1)
|
|||
|
|
|
|||
|
|
excel_path = os.path.expanduser(sys.argv[1])
|
|||
|
|
if not os.path.exists(excel_path):
|
|||
|
|
print(f"ERROR: 文件不存在: {excel_path}", file=sys.stderr)
|
|||
|
|
sys.exit(1)
|
|||
|
|
|
|||
|
|
# 解析 --output
|
|||
|
|
output = None
|
|||
|
|
if '--output' in sys.argv:
|
|||
|
|
idx = sys.argv.index('--output')
|
|||
|
|
if idx + 1 < len(sys.argv):
|
|||
|
|
output = sys.argv[idx + 1]
|
|||
|
|
elif '-o' in sys.argv:
|
|||
|
|
idx = sys.argv.index('-o')
|
|||
|
|
if idx + 1 < len(sys.argv):
|
|||
|
|
output = sys.argv[idx + 1]
|
|||
|
|
|
|||
|
|
# 解析 --count(默认6)
|
|||
|
|
count = 6
|
|||
|
|
if '--count' in sys.argv:
|
|||
|
|
idx = sys.argv.index('--count')
|
|||
|
|
if idx + 1 < len(sys.argv):
|
|||
|
|
try:
|
|||
|
|
count = int(sys.argv[idx + 1])
|
|||
|
|
except ValueError:
|
|||
|
|
pass
|
|||
|
|
elif '-n' in sys.argv:
|
|||
|
|
idx = sys.argv.index('-n')
|
|||
|
|
if idx + 1 < len(sys.argv):
|
|||
|
|
try:
|
|||
|
|
count = int(sys.argv[idx + 1])
|
|||
|
|
except ValueError:
|
|||
|
|
pass
|
|||
|
|
|
|||
|
|
top6 = select_top6(excel_path, count=count)
|
|||
|
|
|
|||
|
|
print(f"筛选完成,共 {len(top6)} 条视频:")
|
|||
|
|
for i, v in enumerate(top6):
|
|||
|
|
print(f" {i+1}. {v['视频标题'][:30]}... | 赞:{v['点赞数']} 转:{v['分享数']} | {v['视频时长']} | {v['发布时间']}")
|
|||
|
|
|
|||
|
|
if output:
|
|||
|
|
with open(output, 'w', encoding='utf-8') as f:
|
|||
|
|
json.dump(top6, f, ensure_ascii=False, indent=2)
|
|||
|
|
print(f"\n已保存到: {output}")
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
main()
|