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:
1 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#!/usr/bin/env python # -*- coding: utf-8 -*- import mechanize import cookielib import re 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 while True: try: #Preparing cookies cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) #Browser options br.set_handle_equiv(True) br.set_handle_gzip(False) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) #Emulating firefox br.addheaders = [('User-agent', 'Mozilla/5.0 (X11;\ U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615\ Fedora/3.0.1-1.fc9 Firefox/3.0.1')] br.open(url) #Getting the login form br.select_form(nr=0) # Filling the form values to submit br.form['email'] = email br.form['password'] = password br.submit() #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) br.follow_link(link) print "Collected Successfully!" #Time for next retry (in seconds): 24h*60m*60s sleep(24*60*60) except Exception, e: print "Couldn't collect. Trying again in ", delay_time/60 ,"minute(s)." sleep(delay_time) |
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.
1 Comment
Sannytet
December 12th, 2018 at 00:29Nice posts! 🙂
___
Sanny