PoshCode Logo PowerShell Code Repository

Get-JackPot by Craig Dayton 3 weeks ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6828"></script>download | new post

PowerShell script for displaying and picking Washington State lottery game winning numbers.
https://github.com/cadayton/JackPot
https://www.powershellgallery.com/packages/Get-JackPot/2.1.1/DisplayScript

  1. <#PSScriptInfo
  2.  
  3.   .VERSION 2.1.1
  4.   .GUID 0fd916fe-3a0d-48c4-a196-18ea085e071f
  5.   .AUTHOR Craig Dayton
  6.   .COMPANYNAME Example.com
  7.   .COPYRIGHT Absolute Zero
  8.   .TAGS
  9.   .LICENSEURI
  10.   .PROJECTURI https://github.com/cadayton/JackPot
  11.   .ICONURI
  12.   .EXTERNALMODULEDEPENDENCIES
  13.   .REQUIREDSCRIPTS
  14.   .EXTERNALSCRIPTDEPENDENCIES
  15.   .RELEASENOTES
  16.  
  17. #>
  18.  
  19. <#
  20.   .SYNOPSIS
  21.     Display the current Washington State lottery game results and optionally stores the
  22.     results in a local history file.
  23.  
  24.   .DESCRIPTION
  25.     Displays Washington lottery game results by invoking a web request to
  26.     http://www.walottery.com/WinningNumbers and extracts the game results
  27.     onto the console and optionally saves the results locally.
  28.  
  29.     Picks game winning numbers based on frequency of past winning numbers.
  30.  
  31.   .PARAMETER game
  32.     Displays all the history results of a specified lottery game in the Out-Gridview.
  33.  
  34.     When used in combination with the '-picker' option, will select a set numbers to
  35.     be played for the specified game.
  36.  
  37.   .PARAMETER online
  38.     Displays the current lottery game results on the console.
  39.  
  40.   .PARAMETER update
  41.     Displays the current lottery game results on the console and updates
  42.     the history file.
  43.  
  44.     When used in combination with '-online' option, will compare the winning
  45.     numbers to the numbers selected using the '-picker' and report on the number
  46.     of matches.
  47.  
  48.   .PARAMETER all
  49.     Displays all the history lottery game results in a Out-Gridview.
  50.  
  51.   .PARAMETER picker
  52.     Used in combination with the 'game' option to pick a set of winning
  53.     numbers for a game based on frequency of past winning numbers.
  54.  
  55.     If the '-all' option is used in combintion with the '-picker' option then
  56.     then all potential game numbers will be candidates for selection.
  57.  
  58.     To restore the number selection process back to only selecting from
  59.     the most frequently used numbers for a game, the file, JackPot-HotNums.csv
  60.     must be deleted.
  61.  
  62.   .PARAMETER picks
  63.     Displays the history of past games that have been played.
  64.  
  65.  
  66.   .PARAMETER count
  67.     Used in combination with the 'game' and 'picker' option to generate
  68.     a specified set of numbers.  The default is 1.
  69.  
  70.   .INPUTS
  71.     A history csv file named, JackPot-Results.csv
  72.  
  73.     http://www.walottery.com/WinningNumbers
  74.  
  75.   .OUTPUTS
  76.     A history csv file named, JackPot-Results.csv
  77.  
  78.   .EXAMPLE
  79.  
  80.     The ordering of the examples below is the typically workflow
  81.     when placing lottery game bets.
  82.    
  83.     It is not necessary to actually purchase any game tickets, but one can
  84.     just play along as though a purchase was made.
  85.  
  86.     I doubt this code is providing any increase in the odds of winning any
  87.     specific game.
  88.    
  89.     It will though greatly reduce the time it takes to sort out any winning
  90.     matches from multiple tickets.  Provided one is using this code to
  91.     select the game numbers.
  92.  
  93.   .EXAMPLE
  94.     Get-JackPot -update
  95.  
  96.     Queries the lottery web page and then extracts and displays the
  97.     current game results.  The history file, JackPot-Result.csv is then
  98.     updated with new game results.
  99.  
  100.     Routinely running this command build a local copy of all the lottery
  101.     games.
  102.  
  103.   .EXAMPLE
  104.     Get-JackPot -update -picker -game PowerBall -count 2
  105.  
  106.       Generates 2 sets winning numbers for the 'PowerBall' game
  107.       and places the bets into the file, JackPot-Picks.csv.
  108.      
  109.       The numbers are randomly selected from the game entries in the
  110.       file, JackPot-HotNums.csv.  This file consists of the most
  111.       frequently selected winning numbers for the game.
  112.  
  113.       These numbers need to be generated on the same day as the
  114.       drawing is being held.
  115.  
  116.     Get-JackPot -update -picker -all -game MegaMillions
  117.  
  118.       The '-all' option sets the default selection of game numbers
  119.       to be all possible numbers for the game.
  120.  
  121.       Delete the file, JackPot-HotNums.csv to restore the game selection
  122.       of numbers to the most frequently selected numbers for the game.
  123.  
  124.     Example Output:
  125.       PowerBall Game (1):  16 23 25 32 64 09
  126.       PowerBall Game (2):  25 28 40 52 64 21
  127.  
  128.     With these numbers in hand, go to your local lottery store
  129.     and complete the game card.
  130.  
  131.     By default only the most frequent winning numbers for the game
  132.     are candidiates for selection.  The default selection process
  133.     can be overridden by specified '-all' option.
  134.  
  135.     Once the '-all' is specified that method becomes the new default.
  136.     To switch back to the prior default the file, JackPot-HotNums.csv
  137.     must be deleted.
  138.  
  139.     Valid games are 'PowerBall', 'MegaMillions', 'Lotto', 'Hit5', 'Match4',
  140.     and 'DailyGame'.
  141.  
  142.   .EXAMPLE
  143.     Get-JackPot -online -update
  144.  
  145.     Queries the lottery web page and then extracts and displays the
  146.     current game results.
  147.    
  148.     Next the winning results are compared to the picked numbers for the
  149.     game and a report is generated showing of balls matched per game.
  150.  
  151.     The recent game picks in the file, JackPot-Picks.csv are updated
  152.     with the winning results and match count then moved to the file,
  153.     JackPot-PickHostory.csv. Afterwards, the JackPot-Picks.csv file is
  154.     removed.
  155.  
  156.   .EXAMPLE
  157.     Get-JackPot
  158.  
  159.     Displays the last 12 game history records on the console.
  160.  
  161.   .EXAMPLE
  162.     Get-JackPot -game PowerBall
  163.  
  164.     Displays all the PowerBall records in the history file.
  165.  
  166.   .EXAMPLE
  167.     Get-JackPot -online
  168.  
  169.     Queries the lottery web page and then extracts and displays the
  170.     current game results.
  171.  
  172.   .EXAMPLE
  173.     Get-JackPot -picks
  174.  
  175.     Displays history of the games played compared to the drawing results.
  176.  
  177.   .NOTES
  178.     Author: Craig Dayton
  179.       2.1.1: 04/01/2017 - Fixed logic errors & updated embeded documentation
  180.       2.1.0: 03/27/2017 - Added feature to evaluate picked numbers against winning numbers
  181.       2.0.0: 03/24/2017 - Added feature to generate a set of winning numbers
  182.       1.0.2: 03/24/2017 - Game record duplication algorthim modified
  183.       1.0.1: 03/23/2017 - Fixed some logic errors
  184.       1.0.0: 03/22/2017 - initial release.
  185.    
  186. #>
  187.  
  188.  
  189. # Get-JackPot Params
  190.   [cmdletbinding()]
  191.     Param(
  192.       [Parameter(Position=0,
  193.         Mandatory=$false,
  194.         HelpMessage = "Enter a lottery game name (i.e. PowerBall)",
  195.         ValueFromPipeline=$True)]
  196.         #[ValidateNotNullorEmpty("^[a-zA-Z]{12}$")]
  197.         [string]$game,
  198.       [Parameter(Position=1,
  199.         Mandatory=$false,
  200.         HelpMessage = "Display Online Lottery Results",
  201.         ValueFromPipeline=$True)]
  202.         [ValidateNotNullorEmpty()]
  203.         [switch]$online,
  204.       [Parameter(Position=2,
  205.         Mandatory=$false,
  206.         HelpMessage = "Display Online Lottery Results & update history file",
  207.         ValueFromPipeline=$True)]
  208.         [ValidateNotNullorEmpty()]
  209.         [switch]$update,
  210.       [Parameter(Position=3,
  211.         Mandatory=$false,
  212.         HelpMessage = "Display all game history file records",
  213.         ValueFromPipeline=$True)]
  214.         [ValidateNotNullorEmpty()]
  215.         [switch]$all,
  216.       [Parameter(Position=4,
  217.         Mandatory=$false,
  218.         HelpMessage = "Display all game history file records",
  219.         ValueFromPipeline=$True)]
  220.         [ValidateNotNullorEmpty()]
  221.         [switch]$picker,
  222.       [Parameter(Position=5,
  223.         Mandatory=$false,
  224.         HelpMessage = "Display the pick history of all games",
  225.         ValueFromPipeline=$True)]
  226.         [ValidateNotNullorEmpty()]
  227.         [switch]$picks,
  228.       [Parameter(Position=6,
  229.         Mandatory=$false,
  230.         HelpMessage = "Number of games",
  231.         ValueFromPipeline=$True)]
  232.         [ValidateNotNullorEmpty()]
  233.         [int]$count = 1
  234.    )
  235. #
  236.  
  237. # Declarations
  238.   $URI1 = "http://www.walottery.com/WinningNumbers";
  239.  
  240.   [String[]]$JackPotHeader  = "Game", "DrawDate","DrawDay", "Numbers", "Multiplier", "JackPot", "NextDraw", "NextDay";
  241.   [String[]]$MultiHeader    = "Game", "HotNums","Multiplier";
  242.   [String[]]$StdHeader      = "Game", "HotNums";
  243.   [String[]]$DailyHeader    = "Game", "Pos1","Pos2","Pos3";
  244.   [String[]]$PickHeader     = "Game", "PickDate","PickDay","Choices","Cost","WinNums","Matches","Prize","Multiplier";
  245.  
  246.   # Top frequent winning numbers per game
  247.     $HotArray = New-Object System.Collections.ArrayList;
  248.     $HotArray.Add('PowerBall,03 12 16 23 25 28 32 33 40 52 64 69,02 03 05 06 09 10 12 17 19 20 21 25') | Out-Null;
  249.     $HotArray.Add('MegaMillions,02 11 20 25 29 31 35 41 44 45 49 51,01 02 03 04 06 07 08 09 10 12 14 15') | Out-Null;
  250.     $HotArray.Add('Lotto,28 26 03 37 47 13 17 27 39 49 19 25 43 21 20 08 41 12 01 24 10') | Out-Null;
  251.     $HotArray.Add('Hit5,35 37 13 33 14 23 17 12 27 07 28 02 21 03 11 34 38 10 31') | Out-Null;
  252.     $HotArray.Add('Match4,19 18 24 05 13 08 04 02 16 07 21 06') | Out-Null;
  253.     $HotArray.Add('DailyGame,8 5 4 7 1,7 2 9 6 5,8 0 1 2 4') | Out-Null;
  254.   #
  255.  
  256.   # All game numbers
  257.     $AllArray = New-Object System.Collections.ArrayList;
  258.     $AllArray.Add('PowerBall,01 02 03 04 05 06 07 08 09 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,01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26') | Out-Null;
  259.     $AllArray.Add('MegaMillions,01 02 03 04 05 06 07 08 09 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,01 02 03 04 06 07 08 09 10 12 14 15') | Out-Null;
  260.     $AllArray.Add('Lotto,01 02 03 04 05 06 07 08 09 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') | Out-Null;
  261.     $AllArray.Add('Hit5,01 02 03 04 05 06 07 08 09 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') | Out-Null;
  262.     $AllArray.Add('Match4,01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24') | Out-Null;
  263.     $AllArray.Add('DailyGame,1 2 3 4 5 6 7 8 9,1 2 3 4 5 6 7 8 9,1 2 3 4 5 6 7 8 9') | Out-Null;
  264.   #
  265.  
  266. #
  267.  
  268. # Functions
  269.  
  270.   function Convert-fileToCSV {
  271.     param ([string]$fname)
  272.  
  273.     $bufLine  = $null;
  274.     $game = $Global:game;
  275.     [bool]$needNums = $true;
  276.     $DrawDate, $DrawDay, $Numbers, $Multiplier, $Prize, $NextDate, $NextDay = $null;
  277.  
  278.     get-content -Path $fname | ForEach-Object {  # process each input line
  279.       # evaluate any non-blank line
  280.       if ($_ -notmatch "^ ") {
  281.         $curLine = $_;
  282.        
  283.         if ($curLine -match "Latest Draw:" -and $DrawDate -eq $null) {
  284.           $junk,$ld = $curline.Split(":");
  285.           $day,$date = $ld.Split("/");
  286.           $DrawDay = $day;
  287.           $DrawDate = Get-Date $date -format yyyy-MM-dd;
  288.         }
  289.  
  290.         if ($curLine -match "^\d" -and $needNums) {
  291.           $Numbers += $curLine + " ";
  292.         }
  293.  
  294.         if ($curLine -match "Power Play" -and $Multiplier -eq $null) {
  295.           $Multiplier = $curLine.Substring(11,3);
  296.         }
  297.  
  298.         if ($curLine -match "Megaplier" -and $Multiplier -eq $null) {
  299.           $Multiplier = $curLine.Substring(10,3);
  300.         }
  301.  
  302.         if ($curLine -match "[$]" -and $Prize -eq $null) {
  303.           $needNums = $false;
  304.           $Prize = $curLine;
  305.         }
  306.  
  307.         if ($curLine -match "Next Draw:" -and $NextDate -eq $null) {
  308.           $junk,$ld = $curline.Split(":");
  309.           $day,$date = $ld.Split("/");
  310.           if ($date -ne $null ) {
  311.             $NextDay = $day;
  312.             $NextDate = Get-Date $date -format yyyy-MM-dd;
  313.           } else {
  314.             $NextDate = $day;
  315.           };
  316.         }
  317.  
  318.         if ($curLine -match "Daily" -and $NextDate -eq $null) { $NextDate = $curLine};
  319.  
  320.       }
  321.     }
  322.  
  323.     $bufLine  = $game + ";" + $DrawDate + ";" + $DrawDay + ";" + $Numbers + ";";
  324.     $bufLine += $Multiplier + ";" + $Prize + ";" + $NextDate + ";" + $NextDay;
  325.     $bufLine | Out-File -FilePath $temp2 -Append -Encoding ascii;
  326.  
  327.     if (Test-Path $fname) { Remove-Item -Path $fname };
  328.  
  329.   }
  330.  
  331.   function Update-JackPotHistory {
  332.     param ([string]$fname)
  333.  
  334.     if (Test-Path $JackPot ) {
  335.    
  336.       $histLine  = Get-Content -Path $JackPot | Select-Object -Last 1;
  337.       $currLine  = Get-Content -Path $fname | Select-Object -Last 1;
  338.  
  339.       if ($histLine -ne $currLine) { # Update history file
  340.         $histLine  = Get-Content -Path $JackPot | Select-Object -Last 12;
  341.         get-content -Path $fname | ForEach-Object {  # process each input line
  342.           $curLine    = $_;
  343.           $curLine24  = $_.Substring(0,23);
  344.           [bool]$duplicate = $false;
  345.           # Elimate duplcate entries in the history file
  346.           $histLine | ForEach-Object {
  347.             $histLine24 = $_.Substring(0,23);
  348.             if ($curLine24 -eq $histLine24) {
  349.               $duplicate = $true;
  350.             }
  351.           }
  352.           if ($duplicate) {} else {
  353.             $curLine | Out-File -FilePath $JackPot -Append -Encoding ascii;
  354.           }
  355.         }
  356.       }
  357.     } else {
  358.       get-content -Path $fname | ForEach-Object {  # process each input line
  359.         $_ | Out-File -FilePath $JackPot -Append -Encoding ascii;
  360.       }
  361.     }
  362.   }
  363.  
  364.   function Get-Matches {
  365.     param([string]$pickGame, [string]$choices, [string]$winners)
  366.  
  367.     $c1 = $choices.Split(" ");
  368.     $w1 = $winners.Split(" ");
  369.     [int]$matchcnt    = 0;
  370.     [int]$gameBall    = 0;
  371.     [int]$lastIdx     = $w1.Length - 1;
  372.     [int[]]$matchRslt = 0,0;
  373.  
  374.     for ($i = 0;$i -le $lastIdx; $i++) {
  375.       for ($j = 0; $j -le $lastIdx; $j++) {
  376.         if ($c1[$i] -eq $w1[$j]) {
  377.           $matchcnt++
  378.           if ($pickGame -eq "PowerBall" -or $pickGame -eq "MegaMillions") {
  379.             if ($i -eq $lastIdx -and $j -eq $lastIdx) {$gameBall++; $matchcnt--; }
  380.           }
  381.         }
  382.       }
  383.     }
  384.  
  385.     $matchRslt[0] = $matchcnt;  $matchRslt[1] = $gameBall;
  386.     return $matchRslt;
  387.  
  388.   }
  389.  
  390.   function Update-PickHistory {
  391.     param ([string]$fname)
  392.  
  393.     if (Test-Path $curPicks ) {
  394.    
  395.       $currentGames = Import-CSV -Path $fname -Delimiter ";" -Header $JackPotHeader;
  396.       $currentPicks = Import-CSV -Path $curPicks -Delimiter ";" -Header $PickHeader;
  397.       $pickResults = @();
  398.  
  399.       Write-Host "Checking prior games for matching numbers..." -ForegroundColor Yellow;
  400.  
  401.       $currentGames | ForEach-Object {
  402.         [bool]$gameBallMatch = $false;
  403.         $curGame = $_;
  404.         $curGameName = $_.Game + $_.DrawDate;
  405.         #[int]$cmpSize = ($gameName.Length + 11) - 1;
  406.         #$curGameDate = $_DrawDate;
  407.         $currentPicks | ForEach-Object {
  408.           $curPick = $_;
  409.           $curPickName = $_.Game + $_.PickDate;
  410.           if ($curGameName -eq $curPickName) {
  411.             $curPick.WinNums = $curGame.Numbers;
  412.             if ($curPick.Choices -eq $curGame.Numbers) { # All numbers match!!
  413.               $nums = $curGame.Numbers;
  414.               $cnt = $nums.Split(" ")
  415.               $curPick.Matches = $cnt.Length;
  416.               $gameBallMatch = $true;
  417.               $color = "Red";
  418.             } else { # count matching numbers
  419.               $matches = Get-Matches $curPick.Game $curPick.Choices $curPick.WinNums;
  420.               $curPick.Matches = $matches[0];
  421.               if ($matches[0] -gt 0) { $color = "Green"} else { $color = "Blue"}
  422.               if ($matches[1] -gt 0) { $gameBallMatch = $true; $color1 = "Green"} else {$color1 = "Blue"}
  423.             }
  424.             if ($curPick.Game -eq "PowerBall" -or $curPick.Game -eq "MegaMillions" ) {
  425.               $curPick.Multiplier = $curGame.Multiplier;
  426.             } else {
  427.               $curPick.Multiplier = "NA";
  428.             };
  429.             $curPick | Export-CSV -Path $PickHis -Delimiter "," -Append -NoTypeInformation
  430.             $pickResults += $curPick;
  431.           }
  432.         }
  433.       }
  434.       $pickResults | Format-Table -Auto
  435.       Write-Host "Check $URI1 for the amount won for each match" -ForegroundColor Green
  436.       Remove-Item -Path $curPicks
  437.     }
  438.   }
  439.  
  440.   function Get-WaWebRequest {
  441.    
  442.     $response = Invoke-WebRequest -URI $URI1;
  443.  
  444.     if ($response.StatusCode -eq "200") {
  445.       Write-Progress -Activity "Processing response from $URI1 ..." -Status "Please wait"
  446.  
  447.       $Global:game = "PowerBall";
  448.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  449.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  450.                 Where-Object classname -eq "game-bucket game-bucket-powerball"
  451.               );
  452.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  453.       Convert-fileToCSV $temp1;
  454.  
  455.       $Global:game = "MegaMillions";
  456.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  457.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  458.                 Where-Object classname -eq "game-bucket game-bucket-megamillions"
  459.               );
  460.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  461.       Convert-fileToCSV $temp1;
  462.  
  463.       Write-Progress -Activity "Done" -Completed;
  464.  
  465.       $Global:game = "Lotto";
  466.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  467.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  468.                 Where-Object classname -eq "game-bucket game-bucket-lotto"
  469.               );
  470.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  471.       Convert-fileToCSV $temp1;
  472.  
  473.       $Global:game = "Hit5";
  474.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  475.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  476.                 Where-Object classname -eq "game-bucket game-bucket-hit5"
  477.               );
  478.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  479.       Convert-fileToCSV $temp1;
  480.  
  481.       $Global:game = "Match4";
  482.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  483.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  484.                 Where-Object classname -eq "game-bucket game-bucket-match4"
  485.               );
  486.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  487.       Convert-fileToCSV $temp1;
  488.  
  489.       $Global:game = "DailyGame";
  490.       Write-Host " Processing $Global:game results"  -ForegroundColor Green
  491.       $data = $($response.ParsedHtml.getElementsByTagName("div") |
  492.                 Where-Object classname -eq "game-bucket game-bucket-dailygame"
  493.               );
  494.       $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  495.       Convert-fileToCSV $temp1;
  496.  
  497.       <# commented out Keno
  498.         $Global:game = "Keno"; $Global:ID = 7;
  499.         Write-Host " Processing $Global:game results"  -ForegroundColor Green
  500.         $data = $($response.ParsedHtml.getElementsByTagName("div") |
  501.                   Where-Object classname -eq "game-bucket game-bucket-keno"
  502.                 );
  503.         $data.innerText | Out-File -FilePath $temp1 -Append -Encoding ascii;
  504.         Convert-fileToCSV $temp1;
  505.       #>
  506.  
  507.       $currentGames = Import-CSV -Path $temp2 -Delimiter ";" -Header $JackPotHeader;
  508.       $currentGames | Format-Table -AutoSize -Wrap
  509.  
  510.       if ($update) { Update-JackPotHistory $temp2; };
  511.       if ((Test-Path $curPicks) -and $online -and $update) { Update-PickHistory $temp2 };
  512.  
  513.       if (Test-Path $temp2 ) {
  514.         Remove-Item -Path $temp2
  515.       };
  516.  
  517.     } else {
  518.       Write-Host "Received error code: $response.StatusCode from $URI1";
  519.     }
  520.  
  521.   }
  522.  
  523.   function Show-JackPotError {
  524.     Write-Host "$JackPot not found"
  525.     Write-Host "Execute 'Get-JackPot -update' to create the history file."
  526.     Write-Host "Get-Help Get-JackPot -full and review the documentation."
  527.   }
  528.  
  529.   function Get-MultiPicker {
  530.     $HotPB = Import-CSV -Path $HotNums -Delimiter "," -Header $MultiHeader |
  531.       Where-Object {$_.Game -match $game };
  532.     for ($i = 1; $i -le $count; $i++) {
  533.       $topNums  = $HotPB.HotNums;
  534.       $topMulti = $HotPB.Multiplier;
  535.       $top1     = $topNums.Split(" ");
  536.       $top2     = $topMulti.Split(" ");
  537.       $sel1     = Get-Random -InputObject $top1 -Count 5
  538.       $sel2     = Get-Random -InputObject $top2 -Count 1
  539.       $sela     = $sel1 | Sort-Object;
  540.       $selb     = [system.String]::Join(" ",$sela)
  541.       $sel      = $selb + " " + $sel2;
  542.       Write-Host "$game Game ($i):  $sel" -ForegroundColor Green
  543.       if ($update) {
  544.         $dt = Get-Date -format "yyyy-MM-dd";
  545.         $da = Get-Date -uformat %a;
  546.         $da = " " + $da.ToUpper();
  547.         $grec = $game + ";" + $dt + ";" + $da + ";" + $sel + ";;;";
  548.         $grec | Out-File -FilePath $curPicks -Append -Encoding ascii;
  549.       }
  550.     }
  551.   }
  552.  
  553.   function Get-NumPicker {
  554.     Param ([int]$numcnt)
  555.  
  556.     $HotPB = Import-CSV -Path $HotNums -Delimiter "," -Header $StdHeader |
  557.       Where-Object {$_.Game -match $game };
  558.  
  559.     for ($i = 1; $i -le $count; $i++) {
  560.       $topNums  = $HotPB.HotNums;
  561.       $top1     = $topNums.Split(" ");
  562.       $sel1     = Get-Random -InputObject $top1 -Count $numcnt
  563.       $sela     = $sel1 | Sort-Object;
  564.       $selb     = [system.String]::Join(" ",$sela)
  565.       Write-Host "$game Game ($i):  $selb" -ForegroundColor Green
  566.       if ($update) {
  567.         $dt = Get-Date -format "yyyy-MM-dd";
  568.         $da = Get-Date -uformat %a;
  569.         $da = " " + $da.ToUpper();
  570.         $grec = $game + ";" + $dt + ";" + $da + ";" + $selb + ";;;";
  571.         $grec | Out-File -FilePath $curPicks -Append -Encoding ascii;
  572.       }
  573.     }
  574.   }
  575.  
  576.   function Get-GameNumbers {
  577.  
  578.     if ($all) {
  579.       if (Test-Path $HotNums) { Remove-Item -Path $HotNums }
  580.       $AllArray | ForEach-Object {
  581.         $_ | Out-File -FilePath $HotNums -Append -Encoding ascii;
  582.       }
  583.     }
  584.  
  585.     if (Test-Path $HotNums) {} else {
  586.       # Create the file dynamically
  587.       $HotArray | ForEach-Object {
  588.         $_ | Out-File -FilePath $HotNums -Append -Encoding ascii;
  589.       }
  590.     }
  591.  
  592.     switch ($game) {
  593.       "PowerBall" {
  594.         Get-MultiPicker;
  595.       }
  596.       "MegaMillions" {
  597.         Get-MultiPicker;
  598.       }
  599.       "Lotto" {
  600.         Get-NumPicker 6
  601.       }
  602.       "Hit5" {
  603.         Get-NumPicker 5
  604.       }
  605.       "Match4" {
  606.         Get-NumPicker 4
  607.       }
  608.       "DailyGame" {
  609.         $HotPB = Import-CSV -Path $HotNums -Delimiter "," -Header $DailyHeader |
  610.           Where-Object {$_.Game -match $game };
  611.         for ($i = 1; $i -le $count; $i++) {
  612.           $topPos1  = $HotPB.Pos1;
  613.           $topPos2  = $HotPB.Pos2;
  614.           $topPos3  = $HotPB.Pos3;
  615.           $pos1     = $topPos1.Split(" ");
  616.           $pos2     = $topPos2.Split(" ");
  617.           $pos3     = $topPos3.Split(" ");
  618.           $sel1     = Get-Random -InputObject $pos1 -Count 1
  619.           $sel2     = Get-Random -InputObject $pos2 -Count 1
  620.           $sel3     = Get-Random -InputObject $pos3 -Count 1
  621.           $sel      = $sel1 + " " + $sel2 + " " + $sel3;
  622.           Write-Host "$game Game ($i):  $sel" -ForegroundColor Green
  623.           if ($update) {
  624.             $dt = Get-Date -format "yyyy-MM-dd";
  625.             $da = Get-Date -uformat %a;
  626.             $da = " " + $da.ToUpper();
  627.             $grec = $game + ";" +$dt + ";" + $da + ";" + $sel + ";;;";
  628.             $grec | Out-File -FilePath $curPicks -Append -Encoding ascii;
  629.           }
  630.         }
  631.  
  632.       }
  633.       Default {
  634.         Write-Host "$game not found" -ForegroundColor Red
  635.         Write-Host "Valid game names are: 'PowerBall, MegaMillions, Hit5, Match4, and DailyGame' " -ForegroundColor Green
  636.       }
  637.     }
  638.  
  639.   }
  640.  
  641. #
  642.  
  643. # Main Routine
  644.  
  645.   $sPath    = Get-Location;
  646.   $temp1    = "$sPath\temp1.txt";
  647.   $temp2    = "$sPath\temp2.txt";
  648.   $JackPot  = "$sPath\JackPot-Results.csv";
  649.   $HotNums  = "$sPath\JackPot-HotNums.csv";
  650.   $curPicks    = "$sPath\JackPot-Picks.csv";
  651.   $PickHis  = "$sPath\JackPot-PickHistory.csv";
  652.  
  653.   if (Test-Path $temp1 ) {
  654.     Remove-Item -Path $temp1
  655.   };
  656.  
  657.   if (Test-Path $temp2 ) {
  658.     Remove-Item -Path $temp2
  659.   };
  660.  
  661.   $choice = $null;
  662.   if ($game -and $picker) { $choice = "GamePicker"}
  663.   elseif ($online -or $update) { $choice = "WebRequest"}
  664.   elseif ($game) { $choice = "GameHistory"}
  665.   elseif ($all) { $choice = "AllHistory"}
  666.   elseif ($picks) { $choice = "PickHistory"}
  667.  
  668.   switch ($choice) {
  669.     "WebRequest" {
  670.       Get-WaWebRequest;
  671.     }
  672.     "GameHistory" {
  673.       if (Test-Path $JackPot) {
  674.         $currentGames = Import-CSV -Path $JackPot -Delimiter ";" -Header $JackPotHeader |
  675.           Where-Object {$_.Game -match $game };
  676.         if ($currentGames) {
  677.           $currentGames |  Out-GridView -Title "$game at $URI1"
  678.         } else {
  679.           Write-Host "$game not found" -ForegroundColor Red
  680.           Write-Host "Valid game names are: 'PowerBall, MegaMillions, Hit5, Match4, and DailyGame' " -ForegroundColor Green
  681.        }
  682.       } else { Show-JackPotError; }
  683.  
  684.     }
  685.     "GamePicker" {
  686.       Get-GameNumbers;
  687.     }
  688.     "AllHistory" {
  689.       if (Test-Path $JackPot) {
  690.         Import-CSV -Path $JackPot -Delimiter ";" -Header $JackPotHeader | Out-GridView -Title "Listing of lottery game records"
  691.       } else { Show-JackPotError; }
  692.     }
  693.     "PickHistory" {
  694.       if (Test-Path $JackPot) {
  695.         $currentPicks = Import-CSV -Path $PickHis
  696.         #$currentPicks | Select-Object | Format-Table -AutoSize -Wrap;
  697.         $currentPicks | Out-GridView -Title "Listing of games played history"
  698.       } else { Show-JackPotError; }
  699.     }
  700.     Default {
  701.       if (Test-Path $JackPot) {
  702.         $currentGames = Import-CSV -Path $JackPot -Delimiter ";" -Header $JackPotHeader;
  703.         $currentGames | Select-Object -Last 12 | Format-Table -AutoSize -Wrap;
  704.       } else { Show-JackPotError; }
  705.     }
  706.   }
  707.  
  708. #

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me