In our geek club aka The Danish PowerShell user group, we always do a lottery in the end, for books or similar.
To draw the correct winner we have been using a script that I have developed.
I have for a long time, promised to release the script so that other user groups or other interested people can use it for fun!
It has amazing ascii graphics and colors!!! It will take you straight back to your C64 loading screen!
The script is a lottery script that takes a file from www.eventbrite.com containing all attendees.
The script need a LEAP Motion device for actually triggering the lottery, for this I have developed a few .NET DLL’s based on a sample from leapmotion.com
You can download the package with Script and files here:
Download “PSUG.DK-LEAP-Lottery-v7.zip” PSUG.DK-LEAP-Lottery-v7.zip – Downloaded 105 times – 727 KB
How to use:
1. Export at list of your users from eventbrite, use the sample file or edit the sample file to contain your users
2. Save the file as names.csv in same directory as this script (and the other files)
3. Connect your LEAP Motion
4. Start script using the shortcut (you might need to edit the shortcut for the location of your script
5. When it was “connected”. Press enter to start the lottery
6. To “turn the dail” use your hand and swipe over the LEAP Motion. The speed of your hand will have influence in how long the “wheel” turns.
Here is the content of the script:
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# # //*************************************************************************** # // ***** Script Header ***** # // # // Solution: # // File: LEAP-Lottery-v7.ps1 # // Author: Jakob Gottlieb Svendsen, Coretech A/S. http://blog.ctglobalservices.com # // Purpose: Lottery script made for Danish PowerShell User group # // www.PSUG.dk # // Designed to be used with a LEAP motion controller and a list over users from eventbrite.com # // # // Usage: LEAP-Lottery-v7.ps1 # // 1. Export at list of your users from eventbrite, use the sample file or edit the sample file to contain your users # // 2. Save the file as names.csv in same directory as this script (and the other files) # // 3. Connect your LEAP Motion # // 4. Start script using the shortcut (you might need to edit the shortcut for the location of your script # // 5. When it was “connected”. Press enter to start the lottery # // 6. To “turn the dail” use your hand and swipe over the LEAP Motion. The speed of your hand will have influence in how long the “wheel” turns. # // # // CORETECH A/S History: # // 0.0.1 JGS 29/02/20XX Can't remember exact date of the first version! # // 7.0.0 JGS 17/06/2015 Cleaned up script, tweaked wheel run time # // Customer History: # // # // ***** End Header ***** # //*************************************************************************** # //---------------------------------------------------------------------------- #// #// Global constant and variable declarations #/ #//---------------------------------------------------------------------------- $DebugPreference = "silentlycontinue" #//---------------------------------------------------------------------------- #// Procedures #//---------------------------------------------------------------------------- Function RunLottery($runLength) { [system.console]::ForegroundColor = "White" #$theEnd = 0..($script:names.Count-1) | Get-Random Write-Debug "Current length: $runLength" $theEnd = $runLength $currentName = 0 $pause = 10 for ($i = 0; $i -le $theEnd;$i++) { Clear-Host Write-Debug "Current length: $runLength" Write-Host "THE PSUG LOTTERY: " $currentName++ if($currentName -ge $script:names.count) {$currentName = 0} for ($j = 5; $j -gt 0;$j--) { Write-host ($script:names[$currentName - $j]).{First Name} ($script:names[$currentName - $j]).{Surname} } Write-host "$($script:names[$currentName].{First Name}) $($script:names[$currentName].{Surname})" -ForegroundColor Yellow -BackgroundColor Black $currentj = $currentName for ($j = 1; $j -le 5;$j++) { if(($currentName + $j) -ge $script:names.count) { Write-host $script:names[$currentName + $j - $script:names.count].{First Name} $script:names[$currentName + $j - $script:names.count].{Surname} } else { Write-host $script:names[$currentName + $j].{First Name} $script:names[$currentName + $j].{Surname}h } } if (($theEnd-30) -le $i) { $pause += 5 } Start-Sleep -Milliseconds $pause } Write-host "" Write-host "" $startTime = Get-Date while (((Get-date)-$startTime).TotalSeconds -le 10) { 1..15 | foreach {[system.console]::ForegroundColor = $_; Write-host "THE WINNER IS $(($script:names[$currentName].{First Name}).ToUpper()) $(($script:names[$currentName].{Surname}).ToUpper()) `r" -nonewline; sleep -Milliseconds 50} $global:winner = $currentName; } Write-host "THE WINNER IS $(($script:names[$currentName].{First Name}).ToUpper()) $(($script:names[$currentName].{Surname}).ToUpper())" $global:complete = $true } Function StartLottery($event) { $global:ready = $true while (!$global:complete) { $event | receive-job start-sleep -Milliseconds 50 } $script:names = $script:names | ? { $_.{Email Address} -ne $script:names[$global:winner].{Email Address} } Read-Host "Press Enter to start next lottery!" Write-host "Ready to Roll!" #Set-PSBreakpoint -Script .\LEAP-Lottery-v5.ps1 -Line 25 $global:ready = $true $global:complete = $false #restart lottery StartLottery $event } #//---------------------------------------------------------------------------- #// Main routines #//---------------------------------------------------------------------------- cd $PSScriptRoot $script:names = Import-Csv .\names.csv -Delimiter "," [System.IO.Directory]::SetCurrentDirectory($pwd) [System.Reflection.Assembly]::LoadFrom("LeapCSharp.NET4.0.dll") [System.Reflection.Assembly]::LoadFrom("GestureListener.dll") [System.IO.Directory]::getCurrentDirectory() $ErrorActionPreference = "stop" $onGesture = { $frame = $controller.Frame(); foreach ($gesture in $frame.Gestures()) { #$gesture $swipe = New-Object Leap.SwipeGesture -Argumentlist $gesture #progress write-Debug "Speed: $($swipe.Speed/10)" if ($global:ready) { $global:ready = $false #$ready = $false $length = 100..150 | %{ $_ + ($swipe.speed/10) } | Get-Random #Start RunLottery $length } } } $global:complete = $false; #Create gesture listener $listener = new-Object GestureListener.GestureListener -ArgumentList 1500 #Create LEAP Controller $controller = New-Object LEAP.Controller -ArgumentList $listener $controller.EnableGesture([Leap.Gesture+GestureType]::TYPESWIPE) #Display connecting status message until connected $i = 1 while (!$controller.IsConnected) { $dots = ("." * $i).PadRight(3) $msg = "Connecting$dots`r" write-host $msg -NoNewline Start-Sleep -Milliseconds 200 if ($i -eq 3) { $i = 1 } else { $i++ } } #Write empty line to make new line for next message write-host "" #Register OnGesture Event, to trigger action $onGesture when a gesture is detected by LEAP. $event = Register-ObjectEvent -InputObject $listener -EventName OnGesture -Action $onGesture -SourceIdentifier "LEAPEvent" Read-Host "Press Enter to start" Write-host "Ready to Roll!" #Start First Lottery StartLottery $event #clean up get-job | remove-job -Force $controller.RemoveListener($listener); $controller.Dispose(); #//---------------------------------------------------------------------------- #// End Script #//---------------------------------------------------------------------------- |
I know that not everyone owns a LEAP motion, this script could be easily edited to be used only using the keyboard and a random “wheel run time”
If you edit the script for this, please post it in the comments.
Otherwise if there is enough requests, I will do it myself! 😉
Go Lottery Go!!
Leave A Comment