2

So what I am trying to do is, upload an image from my computer to Tumblr, then download it again, do some glitch art with it and upload it again. The goal is, to repeat the procedure about 100 times. I want it to always download the latest picture I uploaded so that the result looks like a timeline.

The code I have so far only includes the glitching part and a link to an image which will be downloaded and glitched if you run the code.

import random
import urllib

from BeautifulSoup import BeautifulStoneSoup


def download_an_image(image_url):
    filename = image_url.split('/')[-1]
    urllib.urlretrieve(image_url, filename)

    return filename

def get_random_start_and_end_points_in_file(file_data):
    start_point = random.randint(2600, len(file_data))
    end_point = start_point + random.randint(0, len(file_data) -     start_point)

    return start_point, end_point

def splice_a_chunk_in_a_file(file_data):
    start_point, end_point =   get_random_start_and_end_points_in_file(file_data)
    section = file_data[start_point:end_point]
    repeated = ''

    for i in range(1, random.randint(3,3)):
        repeated += section

    new_start_point, new_end_point =   get_random_start_and_end_points_in_file(file_data)
    file_data = file_data[:new_start_point] + repeated +     file_data[new_end_point:]
    return file_data

def glitch_an_image(local_image):
    file_handler = open(local_image, 'r')
    file_data = file_handler.read()
    file_handler.close()

    for i in range(1, random.randint(2,3)):
        file_data = splice_a_chunk_in_a_file(file_data)

    file_handler = open(local_image, 'w')
    file_handler.write(file_data)
    file_handler.close

    return local_image

if __name__ == '__main__':
    image_url = "https://upload.wikimedia.org/wikipedia/en/thumb/f/f5/Bid_logo.svg/1264px-Bid_logo.svg.png"
    local_image = download_an_image(image_url)
    image_glitch_file = glitch_an_image(local_image)

    print image_glitch_file

Thanks!

Lucas W
  • 43
  • 6

0 Answers0