Gokano is a free web platform for collecting points that can be exchanged for prizes. To participate, the user must register and accomplish some tasks in order to win those points that can be traded when the items are available on stock (it’s worth to say that it’s really competitive ’cause there are too many users for a few items on stock). Among these tasks, some examples are to follow some profiles on social networks, answer to surveys and some other assignments that take benefit from the large number of users of the platform.
Explanation of platform usage
There’s also a task that’s available once a day which is only to click on a button (a well known gamification practice to maintain the users constantly engaged). Once it’s an automated task, we can use a library to implement a script that emulates a web browser. In this post, I’m gonna use Mechanize for Python. You can install it through PIP package manager:
sudo pip install mechanize
In this example, I’m gonna emulate a Mozilla Firefox browser (it’s not really relevant, but in case Gokano’s server stores that information, it will be a valid browser). To run that script, the only arguments you’ll need to provide are the email address and password for your account.
THE SOURCE CODE
# -*- coding: utf-8 -*-
from time import sleep
#Creating browser and setting credentials
br = mechanize.Browser()
url = 'http://www.gokano.com'
email = ''
password = ''
#Delay time for retrying
delay_time = 60
cj = cookielib.LWPCookieJar()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11;\
U; Linux i686; en-US; rv:22.214.171.124) Gecko/2008071615\
#Getting the login form
# Filling the form values to submit
br.form['email'] = email
br.form['password'] = password
#Reading home page and looking for link "Collect daily"
html = br.response().read()
link = br.find_link(text_regex=re.compile("Collect daily"),nr=0)
print "Collected Successfully!"
#Time for next retry (in seconds): 24h*60m*60s
except Exception, e:
print "Couldn't collect. Trying again in ", delay_time/60 ,"minute(s)."
You can notice that the script runs in a loop trying to collect the point and sleeping before making a new attempt. It sleeps for 1 day on success and 1 minute when some error occurs (connection failure, for example). If you want to improve the algorithm, a suggestion would be to daemonize the script, in order to run it on background so you can run it remotely without keeping the console open. I’ll show how to do that in a later post. If you have any doubts or suggestions, please use the comment area or contact me.