No announcement yet.

National Lottery Script

  • Filter
  • Time
  • Show
Clear All
new posts

    National Lottery Script

    I noticed the other day that the BBC site has stopped providing National Lottery data so the script on Jon00's site no longer works. I found an RSS feed for the data so whilst this script is nowhere even approaching what Jon's script did it is a relatively quick and simple way of populating a couple of devices with the lottery results.

    If there was massive interest I can package this up and make it a little special, icons, nice text, device creation etc. For the moment all it does is show the results and does not have many if any options.

    I use the data on a HSTouch screen so am not worried about HS devices as they are hidden, if you also want to show it on HSTouch it is just a matter of status tracking to the devices.

    Before you start you need to;

    1) Reference the System.XML namespace by adding System.XML;System.XML.Dll to your ScriptingReferences line in the settings.ini file. Do not add it again if it is already in there.
    2) Restart HS if you needed to do the above
    3) Create eight status only virtual devices, in sequential order (Q59 - Q65 etc)
    4) Save the script in your scripts folder with a .vb extension
    5) Update the StartUCode and HCode with these values in the script
    6) Update the values on this line with your choices;

    Dim Balls() As Integer = {4, 13, 23, 29, 38, 40}

    7) Run it after every lottery draw, watch the devices update.
    8) Do what you want with the results, sound an alarm, send you a message, set off fireworks, whatever.

    Imports System.XML
    Imports System.Text.RegularExpressions
    Sub Main(ByVal Parms As Object)
    Dim XMLLotto As New XmlDocument
    Dim XMLLottoNodeList As XmlNodeList
    Dim XMLLottoNode As XmlNode
    Dim strResults As String = ""
    Dim strBalls As String
    Dim StrDivide() As String
    Dim i As Integer = 0
    Dim j As Integer = 0
    Dim StartUCode As Integer = 59
    Dim HCode As String = "Q"
    Dim ReturnInt As Integer = 0
    Dim ReturnArr(6) As Integer
    Dim Balls() As Integer = {5, 18, 23, 29, 35, 40}
    XMLLottoNodeList = XMLLotto.SelectNodes("/rss/channel/item")
    For Each XMLLottoNode In XMLLottoNodeList
    If i = 0 Then
    strResults = XMLLottoNode.Item("description").InnerText
    End If
    i = i + 1
    hs.writelog("strResults", strResults)
    strBalls = Right(strResults, (Len(strResults) - Instr(StrResults, ":") - 1))
    hs.writelog("strBalls", strBalls)
    StrDivide = Split(strBalls, ",")
    For i = StartUCode to (StartUCode + 6)
    ReturnArr(j) = Strip(strDivide(i - StartUCode))
    hs.setdevicestring(HCode & i, ReturnArr(j), True)
    hs.setdevicevalue(HCode & i, ReturnArr(j))
    j = j + 1
    If Check(Balls, ReturnArr) = False Then
    hs.setdevicestring(HCode & (StartUCode + 7), "No Win", True)
    hs.setdevicestring(HCode & (StartUCode + 7), "Check Lottery Results", True)
    End If
    End Sub
    Private Function Strip(ByVal value As String) As Integer
    	Dim returnVal As String = String.Empty
    	Dim collection As MatchCollection = Regex.Matches(value, "\d+")
    	For Each m As Match In collection
    		returnVal += m.ToString()
    	Return Convert.ToInt32(returnVal)
    End Function
    Private Function check(ByVal picks As Integer(), ByVal results As Integer()) As Boolean
    Dim numbersMatch As Integer = 0
    For i As Integer = 0 To UBound(picks) - 1
    	For j As Integer = 0 To UBound(results) - 1
    		If picks(i) = results(j) Then		
    		numbersMatch += 1
                    End If
    Select Case numbersMatch
                Case 6
                    Return True
                Case Is < 3
                    Return False
                Case Is >= 3 <= 6
                    Return True
            End Select
    Return False
    End Function
    Seems to work for me, let me know if not.
    Last edited by mrhappy; February 7, 2012, 06:11 PM. Reason: I am not sharing the jackpot with anyone, better take my numbers out.