import os, sys
import Image, ImageGrab, ImageOps
import time, random
from random import randrange
import win32api, win32con
from numpy import *

# Globals
# ------------------

x_pad = 0
y_pad = 0


# Screen Grab Function

def screenGrab():
    b1 = (x_pad + 1,y_pad+1,x_pad+1921,y_pad+1081)
    im = ImageGrab.grab()
    return im

#function for clicking

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

#goes to the third row
    
def thirdRow():
    count = 0
    x=588
    y= 676
    while count <= 3:
        s = screenGrab()
        xy = (x, y)
        s = s.convert('RGB')
        r, g, b = s.getpixel(xy)
    
        if r > 200:
            count += 1
            x += 62
            print "Anti Bot"
            
        elif count <= 3 :
            click(x,y)
            time.sleep(3)
            #win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, x, y, -10000, 0)
            time.sleep(1)
            click(1272,511)
            time.sleep(.5)
            click(1272,551)
            time.sleep(.5)
            click(1272,591)
            time.sleep(2)
            click(1455,310)
            time.sleep(4)
            x += 62
            count += 1

#Goes to the second row
def secondRow():
    count = 0
    x=714
    y=548
    while count <= 3:
        s = screenGrab()
        xy = (x, y)
        s = s.convert('RGB')
        r, g, b = s.getpixel(xy)
    
        if r > 200:
            count += 1
            x += 62
            print "Anti Bot"
            
        elif count <= 3 :
            click(x,y)
            time.sleep(3)
            #win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, x, y, -10000, 0)
            time.sleep(1)
            click(1272,511)
            time.sleep(.5)
            click(1272,551)
            time.sleep(.5)
            click(1272,591)
            time.sleep(2)
            click(1455,310)
            time.sleep(4)
            x += 62
            count += 1


#Main Loop
            
while True:
    count = 0
    x = 590
    y = 420
    while count <= 5:
        
        s = screenGrab()
        xy = (x, y)
        s = s.convert('RGB')
        r, g, b = s.getpixel(xy)

        #Checks for the Anti Botting button, skips if it finds one
        if r > 200:
            count += 1
            x += 62
            print "Anti Bot"

        #All the clicking done here
        elif count <= 5:
            click(x,y)
            time.sleep(3)
            #win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, x, y, -10000, 0)
            time.sleep(1)
            click(1272,511)
            time.sleep(.5)
            click(1272,551)
            time.sleep(.5)
            click(1272,591)
            time.sleep(2)
            click(1455,310)
            time.sleep(4)
            x += 62
            count += 1
    #time.sleep(60)
    secondRow()
    #time.sleep(60)
    thirdRow()
    click(760,813)
    time.sleep(6)
    click(111,16)
    time.sleep(4)
    #time.sleep(55)



#Python Bot for Like4Like.org