__author__ = 'bijan'
from PIL import Image
from io import BytesIO
from authentication import Authentication
import os

GFX_URL = 'http://www.pythonchallenge.com/pc/return/evil2.gfx'
auth = Authentication(GFX_URL, 'huge', 'file')
gfx_read = auth.access()

if not os.path.exists('/12solution'):
    os.makedirs('12solution')

for i in range(5):
    image = gfx_read[i::5]
    image_object = Image.open(BytesIO(image))
    with open("12solution/%d.%s" % (i, image_object.format.lower()), "wb") as imagefile:
        imagefile.write(image)

__author__ = "bijan"
from PIL import Image
from io import BytesIO
from authentication import Authentication

IMAGE_URL = "http://www.pythonchallenge.com/pc/return/cave.jpg"

auth = Authentication(IMAGE_URL)
image = BytesIO(auth.access())
image = Image.open(image)
pix = image.load()
new_image = Image.new(image.mode, image.size)
[new_image.putpixel([i, j], pix[i, j]) for j in range(0, image.size[1], 2) for i in range(0, image.size[0], 2)]
new_image.show()