import os
import time
import zipfile
from datetime import datetime
# pip3 install oss2 -i https://mirrors.aliyun.com/pypi/simple/ requests
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
os.environ['OSS_ACCESS_KEY_ID'] = ''
os.environ['OSS_ACCESS_KEY_SECRET'] = ''
endpoint = 'https://oss-cn-shanghai.aliyuncs.com'
region = "cn-shanghai"
bucket_name = 'bucket1'
## 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
## yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com 。
## 填写Bucket名称。
bucket = oss2.Bucket(auth, endpoint, bucket_name)
# 获取文件大小
def get_file_size_in_mb(file_path):
file_size_bytes = os.path.getsize(file_path)
file_size_mb = round(file_size_bytes / (1024 * 1024), 3) # 将文件大小从字节转换为MB
return file_size_mb
# 获取时间
def get_now_hm():
# 获取当前时间
current_time = dat
06-18
2万+
