# Description: This script is used to update the list of pictures in the Azure Blob Storage container. from azure.storage.blob import BlobServiceClient import os import json def update_pictures(container='tianyi-random', remotedir='', secretdir='/home/tianyi/repos/TianyiMoe/backend/secret.txt', jsondir='/home/tianyi/repos/TianyiMoe/backend/jsons/pics.json'): # print(os.getcwd()) try: with open(secretdir, 'r') as f: connect_str = f.read() blob_service_client = BlobServiceClient.from_connection_string(connect_str) container_client = blob_service_client.get_container_client(container) existing_files=[blob.name.split("/")[-1] for blob in container_client.list_blobs(name_starts_with=remotedir)] print("File number: " + str(len(existing_files))) with open(jsondir, 'w') as f: json.dump(existing_files, f, indent=4, sort_keys=True) except Exception as e: print(e) if __name__ == '__main__': update_pictures()