Skip to content

Instantly share code, notes, and snippets.

@Illizian
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Illizian/89a4d19f5565fbb2156e to your computer and use it in GitHub Desktop.
Save Illizian/89a4d19f5565fbb2156e to your computer and use it in GitHub Desktop.
An Android MonkeyRunner script for keeping Clash of Clan sessions awake
from __future__ import division
from random import randint
#!/usr/bin/python
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from math import log
import time
import commands
import sys
# module functions
def xfrange(start, stop, step):
old_start = start
digits = int(round(log(10000, 10)))+1
magnitude = 10**digits
stop = int(magnitude * stop)
step = int(magnitude * step)
if start == 0:
start = 10**(digits-1)
else:
start = 10**(digits)*start
data = []
end_loop = int((stop-start)//step)
if old_start == 0:
end_loop += 1
acc = start
for i in xrange(0, end_loop):
data.append(acc/magnitude)
acc += step
return data
# module variables
TL = [250, 250] # Co-Ordinates of Top Left Corner
BR = [1600, 800] # Co-Ordinates of Bottom Right Corner
count = 1000 # how many events to send
delay = xfrange(1, 20, 0.01) # min & max delay between events
# starting script
print "Connecting to device..."
# connection to the current device, and return a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
time.sleep(2)
print "Sending "+ str(count) +" events to device..."
for event in range(0, count):
# generate co-ords for event
x = randint(TL[0], BR[0])
y = randint(TL[1], BR[1])
# delay for the configured amount of time
d = delay[randint(0, len(delay)-1)]
# sending an event which simulate a tap
print "["+ str(event) +"] Touching (x: "+ str(x) + " y: "+ str(y) +") and waiting "+ str(d) +"secs"
device.touch(x, y, MonkeyDevice.DOWN_AND_UP)
# sleep for delay
time.sleep(d)
print "Completed sending events"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment