diff --git a/.gitignore b/.gitignore index c12c7e8..ce6e804 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -*.png \ No newline at end of file +*.png +images \ No newline at end of file diff --git a/main.py b/main.py index 0d7ef52..1650c06 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import openai import datetime import requests +import os openai.api_key = "API_TOKEN" @@ -10,6 +11,8 @@ response = openai.Image.create( n = 4, size = "1024x1024" ) +# Create image directory +os.mkdir("images") # Current time current_time = datetime.datetime.now() @@ -19,6 +22,6 @@ for i in range(4): image_url = response['data'][i]['url'] formatDateTime = str(current_time.year) + "-" + str(current_time.month) + "-" + str(current_time.day) + "_" + str(current_time.hour) + "-" + str(current_time.minute) + "-" + str(current_time.second) + "_Image-" + str(i+1) + ".png" img_data = requests.get(image_url).content - with open(formatDateTime, 'wb') as handler: + with open("images/" + formatDateTime, 'wb') as handler: handler.write(img_data) print("Image " + str(i+1) + " saved.") \ No newline at end of file