Skip to content

Instantly share code, notes, and snippets.

@foota
Last active October 2, 2020 16:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foota/6648188 to your computer and use it in GitHub Desktop.
Save foota/6648188 to your computer and use it in GitHub Desktop.
Auto Cookie Clicker. ref. http://orteil.dashnet.org/cookieclicker/
#!/usr/bin/env python
"""
Auto Cookie Clicker by foota, 2013.09.21
ref. http://orteil.dashnet.org/cookieclicker/
"""
import sys, os, time, threading
from pymouse import PyMouse
import ImageGrab
X_POS, Y_POS = 150, 380 # pos. of click
LEFT, RIGHT = 105, 350 # x-range of browser
TOP, BOTTOM = 215, 475 # y-range of browser
WIDTH = RIGHT - LEFT
HEIGHT = BOTTOM - TOP
WAIT_SEARCH_COOKIE = 3 # WAIT_SEARCH_COOKIE * wait_time (sec)
class ClickThread(threading.Thread):
def __init__(self, x_pos, y_pos, num_clicks_once, wait_time):
self.m = PyMouse()
self.x_pos, self.y_pos = x_pos, y_pos
self.num_clicks_once = num_clicks_once
self.wait_time = wait_time
self.is_running = True
threading.Thread.__init__(self)
def check_cookie(self, im):
im = im.crop((LEFT, TOP, RIGHT, BOTTOM))
cx, cy = -1, -1
seq = im.convert("RGB").getdata()
for i, v in enumerate(seq):
if v == (124, 82, 45) or v == (224, 200, 113):
cx, cy = i % WIDTH + LEFT, i / WIDTH + TOP
break
print "Golden Cookie: (%d, %d)" % (cx, cy) #####
return cx, cy
def run(self):
cnt = 0
while self.is_running:
im = ImageGrab.grab()
if cnt % WAIT_SEARCH_COOKIE == 0:
cx, cy = self.check_cookie(im)
if cx >= 0:
self.m.click(cx, cy, 1)
for i in range(self.num_clicks_once):
self.m.click(self.x_pos, self.y_pos, 1)
time.sleep(self.wait_time)
cnt += 1
def finish(self):
self.is_running = False
def clicker(x_pos, y_pos, duration, num_clicks_once, wait_time):
t = ClickThread(x_pos, y_pos, num_clicks_once, wait_time)
t.setDaemon(True)
t.start()
time.sleep(duration)
t.finish()
while t.isAlive(): time.sleep(0.5)
def main(args):
if len(args) < 2:
print >>sys.stderr, "Usage: %s duration [num_clicks_once=100] [wait_time=1.5]" % os.path.basename(args[0])
sys.exit()
duration = float(args[1]) if len(args) >= 2 else 20.0
num_clicks_once = int(args[2]) if len(args) >= 3 else 100
wait_time = float(args[3]) if len(args) >= 4 else 1.5
x_pos, y_pos = X_POS, Y_POS
print "POSITION : (%d, %d)" % (x_pos, y_pos)
print "AREA : (%d, %d)-(%d, %d)" % (LEFT, TOP, RIGHT, BOTTOM)
print "DURATION : %.3f sec (%.3f min)" % (duration, duration / 60.0)
print "WAIT TIME: %.3f sec" % (wait_time,)
print "N_CLICKS : %d" % (num_clicks_once,)
clicker(x_pos, y_pos, duration, num_clicks_once, wait_time)
if __name__ == "__main__": main(sys.argv)
Copy link

ghost commented Oct 2, 2020

Can’t drag spirits in Parthenon on iPad. Could you possibly fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment