Showing posts with label racing. Show all posts
Showing posts with label racing. Show all posts

Thursday, April 26, 2012

Gambling Automation - Workflow design

01.WORKFLOW DESIGN:
          1.01 go to next race
          1.02 get next race time, and wait until 30 seconds before betting close
          1.03 get all the runners info
          1.04 sort runners by odds
          1.05 pick runner by some rules, you can apply your own rules here, I will simply pick the runner got smallest odds
          1.06 bet on win
          1.07 wait until betting close
          1.08 GOT BACK TO '1.01 go to next race' and start a new cycle, stop if predefined condition is met. for example we can ask the program to stop if it has bet 50 races.
02 IMPLEMENT GO TO NEXT RACE: first creat test button, for testing purpose, rename to buttonTest


by using the developer tool in IE 8, we found that the next three races will bring us to an URL which will give us the information about next coming race


create a new method gotoNextRace() in AutoSports.cs, and use browser.goto("url") method, paste the url we just uncovered




now, go to Form1.cs[design], couble click test button we created before, and add the gotoNextRace() method into that block. So program will run gotoNextRace if somebody clicks Test Button.

run the program by pressing F5, after click test button, you should be able to see something like below


Wednesday, April 25, 2012

Gambling Automation - Site Log in

01 UPDATE USER INTERFACE: add button, change text to 'login', change name to 'buttonlogin'
02 CREATE CODE FOR LOGIN:   Click Project-> add class.... , add new class called AutoSports.cs to put the automation methods.
create a login method in it, cut the Browser line created in last post in Form1.cs into AutoSports class, import 3 required packages, add the try block in the new created login method, this will prevent any crash if the login process goes wrong,  add writeLine in the catch block, so if things go wrong you will be informed.

open your ie8, go to http://www.sportsbet.com.au/, and press F12 to bring the developer tool, click the top left arrow and then click user name input box, this will bring you the code behind it, Check the element id is 'username', same you can find id for password box is 'password', and login-button's id is'login-button'.

add the following code into method login, I change browser object name to br, to save typing time. the if sentence is to check if being logged in already. the following lines are straightforward, fill in the info and click the button

go to form1.design change the password textbox to shown stars

create AutoSports object from the AutoSports class we just created in Form1.cs

double click Login button will bring you the code block, fill in the function you want the program to do after you click that button, here we want the program to DO log in


 03 TEST LOGIN: press F5, or click Debug->Start Debugging to try out, you should be able to see the following after click the log in button if you have an account with that site.

05 CODE:
*****************************
AUTOSPORTS.CS
*****************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;
using NUnit.Framework;
using System.Xml.Linq;
namespace sportsbetAuto
{
    class AutoSports
    {
        Browser br = new IE("http://www.sportsbet.com.au/");
        public bool login(string id, string pw)
        {
            try {
                if (!br.Element(Find.ById("log-out")).Exists)//do not login if already logged in
                {  
                    br.Element(Find.ById("username")).SetAttributeValue("value",id);
                    br.Element(Find.ById("password")).SetAttributeValue("value", pw);
                    br.Element(Find.ById("login-button")).Click();
                }
                return true; }
            catch (Exception e){
                System.Console.WriteLine("ERROR! Login Failed!");
                return false;
            }
        }
    }
}
****************
FORM1.CS
***************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WatiN.Core;
using NUnit.Framework;
using System.Xml.Linq;

namespace sportsbetAuto
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        AutoSports autos = new AutoSports();
        public Form1()
        {
            InitializeComponent();
        }
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            autos.login(textBoxLoginID.Text, textBoxPassword.Text);
        }
    }
}