switched docstring format to one-line-sphinx
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# Set your Cloudinary credentials
|
||||
# ==============================
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
@@ -22,10 +21,20 @@ uploader = cloudinary.uploader
|
||||
|
||||
|
||||
class CloudinaryException(Exception):
|
||||
"""
|
||||
Custom exception for Cloudinary errors.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def delete_image(public_id: str) -> None:
|
||||
"""
|
||||
Deletes an image from the Cloudinary cloud.
|
||||
|
||||
:param str public_id: The public ID of the image to delete
|
||||
:raises CloudinaryException: If the image deletion fails
|
||||
"""
|
||||
result = uploader.destroy(public_id)
|
||||
|
||||
if result.get("result") != "ok":
|
||||
@@ -33,16 +42,25 @@ def delete_image(public_id: str) -> None:
|
||||
|
||||
|
||||
def get_image_data(public_id: str) -> dict:
|
||||
"""
|
||||
Retrieves the metadata for an image from the Cloudinary cloud.
|
||||
|
||||
:param str public_id: The public ID of the image to retrieve
|
||||
:return dict: The metadata for the image
|
||||
"""
|
||||
data = cloudinary.api.resource(public_id)
|
||||
return data
|
||||
|
||||
|
||||
def get_image_url(public_id: str) -> str:
|
||||
"""
|
||||
Retrieves the URL for an image from the Cloudinary cloud.
|
||||
|
||||
:param str public_id: The public ID of the image to retrieve
|
||||
:raises CloudinaryException: If the image URL retrieval fails
|
||||
:return str: The URL of the image
|
||||
"""
|
||||
url = cloudinary.utils.cloudinary_url(public_id)[0]
|
||||
if url is None:
|
||||
raise CloudinaryException("Failed to get image URL")
|
||||
return url
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
image_id = "coco_copy_jywbxm"
|
||||
|
||||
Reference in New Issue
Block a user