import json import pathlib
import boto3
def download_s3_obj_versions(_bucket, _key_prefix, _filename, is_save=True): client = boto3.client("s3")
_key = (pathlib.Path(_key_prefix) / _filename).as_posix()
response = client.list_object_versions(Bucket=_bucket, Prefix=_key)
for v in response["Versions"]:
print(v["LastModified"])
if is_save:
_local = (pathlib.Path("/tmp") / _filename).as_posix()
client.download_file(
_bucket,
_key,
_local + "_" + v["LastModified"].strftime("%Y%m%d%H%M%S"),
ExtraArgs={"VersionId": v["VersionId"]},
)
if name == "main": _bucket = "" _filename = "" # e.g.: mysql.pdf _key_prefix = "" # end with '/', e.g.: books/db/mysql
download_s3_obj_versions(_bucket, _key_prefix, _filename, is_save=True)
# check_stream_url("/tmp", "ottera.tcl_tv_plus.all_vod.json_")