Save images in folder
This commit is contained in:
parent
899caab67b
commit
75bffd445c
|
@ -1,2 +1,3 @@
|
|||
.DS_Store
|
||||
*.png
|
||||
*.png
|
||||
images
|
5
main.py
5
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.")
|
Loading…
Reference in New Issue