#!/usr/bin/env python3
"""List COS bucket contents"""
import os, json
os.environ['ZY_OSS_KEY'] = 'AKIDkQuBQhoiS2OYXWebXLwMbdT7cvAScbbU'
os.environ['ZY_OSS_SECRET'] = 'nPoZKArgUJBA4nJenjSxJSQBj5FCj3A4'
from qcloud_cos import CosConfig, CosS3Client
config = CosConfig(Region='ap-guangzhou', SecretId=os.environ['ZY_OSS_KEY'], SecretKey=os.environ['ZY_OSS_SECRET'])
client = CosS3Client(config)
resp = client.list_objects(Bucket='sy-finetune-corpus-1317346199')
print('=== COS存储桶完整内容 ===')
print()
for obj in sorted(resp.get('Contents', []), key=lambda x: x['Key']):
    key = obj['Key']
    size_mb = int(obj['Size']) / 1024 / 1024
    mtime = obj['LastModified'][:19]
    print(f'  {key}  ({size_mb:.1f}MB)  [{mtime}]')
print(f'\n总数: {len(resp.get("Contents", []))} 个文件')
