select image recursive folder #4

This commit is contained in:
Dryusdan 2018-06-23 00:58:57 +02:00
parent 0b27b154b7
commit a5633e5c18
1 changed files with 34 additions and 20 deletions

54
bot.py
View File

@ -29,31 +29,45 @@ blacklist_file.close()
mime_dict = {'.jpg': 'image/jpeg', '.jpe': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.gif': 'image/gif'}
def post_img_local(mastodon, text, log, config):
img_path = get_parameter("img_path", config)
img_path = get_parameter("img_path", config)
continu = True;
while continu:
file = random.choice(os.listdir(img_path+"/"))
if os.path.isdir(file):
img_path = img_path+"/"+file
else:
continu = False
#file = random.choice(os.listdir(img_path+"/"))
image_byte = open(img_path+"/"+file, "rb").read()
continu = True;
while continu:
file = random.choice(os.listdir(img_path+"/"))
if os.path.isdir(img_path+file):
img_path = img_path+file+"/"
else:
if ".zip" not in file:
continu = False
#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:
mime = mime_dict[str.lower(ext)]
except KeyError:
mime = None;
log.error(ext + " is not present on mime_dict, please add this")
pass
try:
mime = mime_dict[str.lower(ext)]
except KeyError:
mime = None;
log.error(ext + " is not present on mime_dict, please add this")
pass
media_dict = mastodon.media_post(image_byte, mime)
return media_dict;
media_dict = mastodon.media_post(image_byte, mime)
return media_dict;
def post_img_distant(mastodon, text, log, config):