UPDATE: the TH11 update will kick you off after a set period known as a "Personal Break Timer", so this no longer works as it did in older versions, feel free to update the code below. Code was just a proof-of-concept anyway.

The below was published 06/04/2015

I posted a video of a Clash of Clans script for "always online" using ADB & Python a while back on Youtube, never did get around to posting the script itself. About time I did i'd say.

Supercell issued an unwarranted copyright takedown against the video that was here

This Clash of Clans script will randomly generate a touch event (providing you have a recent enough version of Android, 4.1+ IIRC) within the bounds of your devices screen, you may configure touch regions within the script. You will need ADB configured and working correctly which is covered elsewhere around the net and will not be covered here. In the video we ran this on a Raspberry Pi as it was more economical than leaving the PC on 24/7. Still the script can be run anywhere you can get python going. The Script
# Clash of Clans farmer

import time
import subprocess
import random
import sys

# General Settings
title = "Clash of Clans"

# Edit depending on you screensize
min_x = 230
max_x = 1030
min_y = 200
max_y = 600

# Interval settings
ilow = 5
ihigh = 29

# ADB settings
adbcmd = 'adb'
adbshell = '%s shell' % adbcmd
adb_it = '%s input tap' % adbshell

def cmd(command, stdout=False):
  ''' execute the commands through Popen
  return the output of popen'''
  command = "%s" % (command)
  proc=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
  if stdout:
    return proc.stdout.read()
    return proc.communicate()[0]

def wstdout(msg):

def setup_tap(x, y):
    interval = random.randint(ilow,ihigh)
    cmd("%s %s %s" % (adb_it, x, y))

def msg_interval(interval):
  while interval > 0:
    wstdout("Next update in %d seconds     \r" % interval)
    interval -= 1
  wstdout("Updating now!                 \r")

def main():
  print "%s, farmer started" % title
  while True:

if __name__ == '__main__':