import boto3
import sys

from botocore.exceptions import BotoCoreError

sys.path.append('./')
from build_script.params import *

target_name = 'sunda-crm-release.apk'
region = 'af-south-1'
bucket = 'smdp-prod'
public_path = 'app-temp/'


def upload_file(file_path, file_name):
    target_file = public_path + file_name

    try:
        s3 = boto3.client('s3', region_name=region, aws_access_key_id=aws_access_key,
                          aws_secret_access_key=aws_secret_key)

        # Upload the file
        s3.upload_file(file_path, bucket, target_file)

        head_url = aws_host_prod + target_file
        return head_url
    except BotoCoreError as e:
        print(f"An error occurred: {e}")
        raise


if __name__ == "__main__":
    # 从命令行参数获取文件路径
    if len(sys.argv) != 3:
        print("Usage: python script.py <文件路径> <对象名称>")
        sys.exit(1)

    file_path = sys.argv[1]
    file_name = sys.argv[2]

    # 上传文件并获URL
    url = upload_file(file_path, file_name)
    print(url)
