select image recursive folder #4
This commit is contained in:
parent
0b27b154b7
commit
a5633e5c18
54
bot.py
54
bot.py
|
@ -29,31 +29,45 @@ blacklist_file.close()
|
||||||
mime_dict = {'.jpg': 'image/jpeg', '.jpe': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.gif': 'image/gif'}
|
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):
|
def post_img_local(mastodon, text, log, config):
|
||||||
img_path = get_parameter("img_path", config)
|
img_path = get_parameter("img_path", config)
|
||||||
|
|
||||||
continu = True;
|
continu = True;
|
||||||
while continu:
|
while continu:
|
||||||
file = random.choice(os.listdir(img_path+"/"))
|
file = random.choice(os.listdir(img_path+"/"))
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(img_path+file):
|
||||||
img_path = img_path+"/"+file
|
img_path = img_path+file+"/"
|
||||||
else:
|
else:
|
||||||
continu = False
|
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)]
|
#mime = mime_dict[str.lower(ext)]
|
||||||
try:
|
try:
|
||||||
mime = mime_dict[str.lower(ext)]
|
mime = mime_dict[str.lower(ext)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
mime = None;
|
mime = None;
|
||||||
log.error(ext + " is not present on mime_dict, please add this")
|
log.error(ext + " is not present on mime_dict, please add this")
|
||||||
pass
|
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):
|
def post_img_distant(mastodon, text, log, config):
|
||||||
|
|
||||||
|
|
Reference in a new issue