Exemplo n.º 1
0
def post():
    files_name = os.listdir(f"{cwd}/photos")
    file = random.choice(files_name)
    split_file_name = str(file).split(".")
    ext = str(split_file_name[1])

    img = Image.open(f"{cwd}/photos/{file}")
    size = img.size

    if not compatible_aspect_ratio(size):
        print("RESIZING IMAGE")
        newsize = (1080, 1080)
        img = img.resize(newsize)
        img.save(f"{cwd}/photos/{file}")

    if ext == 'png':
        img = Image.open(f"{cwd}/photos/{file}")
        jpeg_img = img.convert('RGB')
        jpeg_img.save(f"{cwd}/photos/converted.jpeg")
        bot.upload_photo(f"{cwd}/photos/converted.jpeg", "caption")
        os.remove(f"{cwd}/photos/{file}.REMOVE_ME")
        os.remove(f"{cwd}/photos/converted.jpeg.REMOVE_ME")
    else:
        bot.upload_photo(f"{cwd}/photos/{file}", "caption")

        os.remove(f"{cwd}/photos/{file}.REMOVE_ME")

    if len(files_name) <= 10:
        send_email()
Exemplo n.º 2
0
def pics_generator(pics=[], posted_pic_list=None):
    for pic in pics:
        new_pic = ""
        if pic not in posted_pic_list:
            if not compatible_aspect_ratio(get_image_size(pic)):
                new_pic = resize_image(pic)
            yield pic, new_pic
Exemplo n.º 3
0
def run(message):
    if not message.attachments:
        return None

    if bot is None:
        setup()

    urls = [
        attachment.url for attachment in message.attachments
        if os.path.splitext(attachment.url)[1].lower() in
        ['.jpg', '.jpeg', '.png']
    ]

    url = urls[0]
    img = url_to_image(url)
    img = strip_exif(img).convert('RGB')
    w, h = img.size

    # https://www.tailwindapp.com/blog/instagram-image-size-guide-2020
    if not compatible_aspect_ratio((w, h)):
        img = crop_maximize_entropy(img)

    img.save('instagram_img.jpg', quality=95)
    result = bot.upload_photo('instagram_img.jpg', caption="quack quack")

    if isinstance(result, dict) and 'code' in result:
        return 'Posted! https://www.instagram.com/p/{}'.format(result['code'])
    else:
        return 'Ooops, something went wrong in the upload :('
Exemplo n.º 4
0
def correct_ratio(photo):
    return compatible_aspect_ratio(get_image_size(photo))
Exemplo n.º 5
0
def correct_ratio(photo):
    from instabot.api.api_photo import compatible_aspect_ratio, get_image_size

    return compatible_aspect_ratio(get_image_size(photo))