Save images in folder

This commit is contained in:
Brayd 2023-01-15 15:06:20 +01:00
parent 899caab67b
commit 75bffd445c
Signed by: brayd
GPG Key ID: C2B176B9DEB8BA48
2 changed files with 6 additions and 2 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.DS_Store
*.png
*.png
images

View File

@ -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.")