| import os
|
| import boto3
|
| import urllib3
|
|
|
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
|
| ENDPOINT_URL = 'https://ba1add5d3df1b47fa4893182b8f5761e.eu.r2.cloudflarestorage.comhttps://ba1add5d3df1b47fa4893182b8f5761e.r2.cloudflarestorage.com'
|
| BUCKET_NAME = 'fonts'
|
| ACCESS_KEY_ID = '915b4668f3b146f10a869c753f0d6a12'
|
| SECRET_ACCESS_KEY = 'bcb6246a36b9732a9e1accf3fb7e3004d2cb130f46dd4c393408a3ef4433b869'
|
| LOCAL_DOWNLOAD_DIR = 'downloaded_fonts'
|
|
|
| print(f"Connecting to: {ENDPOINT_URL}")
|
| print(f"Bucket: {BUCKET_NAME}")
|
|
|
| s3 = boto3.client(
|
| 's3',
|
| endpoint_url=ENDPOINT_URL,
|
| aws_access_key_id=ACCESS_KEY_ID,
|
| aws_secret_access_key=SECRET_ACCESS_KEY,
|
| verify=False
|
| )
|
|
|
| if not os.path.exists(LOCAL_DOWNLOAD_DIR):
|
| os.makedirs(LOCAL_DOWNLOAD_DIR)
|
| print(f"Created: {LOCAL_DOWNLOAD_DIR}")
|
|
|
| print("Downloading files...")
|
| paginator = s3.get_paginator('list_objects_v2')
|
| file_count = 0
|
|
|
| try:
|
| for page in paginator.paginate(Bucket=BUCKET_NAME):
|
| if 'Contents' in page:
|
| for obj in page['Contents']:
|
| key = obj['Key']
|
| local_path = os.path.join(LOCAL_DOWNLOAD_DIR, key)
|
|
|
| local_dir = os.path.dirname(local_path)
|
| if local_dir and not os.path.exists(local_dir):
|
| os.makedirs(local_dir)
|
|
|
| print(f" Downloading: {key}")
|
| s3.download_file(BUCKET_NAME, key, local_path)
|
| file_count += 1
|
|
|
| print(f"\n✓ Done! Downloaded {file_count} files to {LOCAL_DOWNLOAD_DIR}")
|
| except Exception as e:
|
| print(f"✗ Error: {e}")
|
|
|