select image recursive folder #4

This commit is contained in:
Dryusdan 2018-06-23 00:58:57 +02:00
parent 0b27b154b7
commit a5633e5c18

24
bot.py
View file

@ -34,15 +34,28 @@ def post_img_local(mastodon, text, log, config):
continu = True;
while continu:
file = random.choice(os.listdir(img_path+"/"))
if os.path.isdir(file):
img_path = img_path+"/"+file
if os.path.isdir(img_path+file):
img_path = img_path+file+"/"
else:
if ".zip" not in file:
continu = False
#file = random.choice(os.listdir(img_path+"/"))
image_byte = open(img_path+"/"+file, "rb").read()
#file, ext = os.path.splittext(img_path+"/"+file)
#if ext in mime_dict:
im = Image.open(img_path+"/"+file)
width, height = im.size
if width > 1980:
ratio_img = width / 1980;
new_width = width / ratio_img
new_height = height / ratio_img
file, ext = os.path.splitext(file)
image = im.resize((int(new_width), int(new_height)))
im.save(img_path+"/"+file)
im.close()
image_byte = open(img_path+"/"+file, "rb").read()
file, ext = os.path.splitext(img_path+"/"+file)
#mime = mime_dict[str.lower(ext)]
try:
@ -55,6 +68,7 @@ def post_img_local(mastodon, text, log, config):
media_dict = mastodon.media_post(image_byte, mime)
return media_dict;
def post_img_distant(mastodon, text, log, config):
collection_url = get_parameter("collection_url", config)