Files
c4c-download/get_ticket_ids.py

32 lines
858 B
Python
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.
#!/usr/bin/env python3
"""从 datasource 目录下的 CSV 文件读取第二列提取10个有效的 Ticket ID"""
import csv
import glob
import os
datasource_dir = os.path.join(os.path.dirname(__file__), "datasource")
csv_files = glob.glob(os.path.join(datasource_dir, "*.csv"))
ids = []
seen = set()
for csv_file in csv_files:
with open(csv_file, encoding="utf-8-sig") as f:
reader = csv.reader(f)
next(reader, None) # 跳过表头
for row in reader:
if len(row) < 2:
continue
val = row[1].strip()
if val and val not in seen:
seen.add(val)
ids.append(val)
if len(ids) >= 10:
break
if len(ids) >= 10:
break
print("找到的 Ticket ID")
for i, tid in enumerate(ids, 1):
print(f" {i}. {tid}")