Created
October 16, 2023 19:42
-
-
Save dimiboy/c7a236d46138d3d0ac9a4e1f873b5bf1 to your computer and use it in GitHub Desktop.
Israel Red Alert PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession | |
$session.Cookies.Add((New-Object System.Net.Cookie("Lastalerts", "", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("AlertSoundNewFeature", "1", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("UsId", "***************", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("_ga_V2BQHCDHZP", "GS1.1.1697037833.1.0.1697037833.60.0.0", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("_ga", "***************", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("_gid", "***************", "/", "www.oref.org.il"))) | |
$session.Cookies.Add((New-Object System.Net.Cookie("_fbp", "***************", "/", "www.oref.org.il"))) | |
$previous = 0 | |
$ProgressPreference = 'SilentlyContinue' | |
function Show-BalloonNotification { | |
param ( | |
[string]$Title, | |
[string]$Text, | |
[int]$DisplayDuration | |
) | |
Add-Type -AssemblyName System.Windows.Forms | |
$balmsg = New-Object System.Windows.Forms.NotifyIcon | |
$path = (Get-Process -id $pid).Path | |
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) | |
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info | |
$balmsg.BalloonTipText = $Text | |
$balmsg.BalloonTipTitle = $Title | |
$balmsg.Visible = $true | |
$balmsg.ShowBalloonTip($DisplayDuration) | |
#$balmsg.Dispose() | |
return $balmsg | |
} | |
while ($true) { | |
Invoke-WebRequest -UseBasicParsing -Uri "https://www.oref.org.il/WarningMessages/alert/alerts.json" ` | |
-WebSession $session ` | |
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0" ` | |
-Headers @{ | |
"Accept" = "*/*" | |
"Accept-Language" = "en-US,en;q=0.5" | |
"Accept-Encoding" = "gzip, deflate, br" | |
"Referer" = "https://www.oref.org.il/" | |
"X-Requested-With" = "XMLHttpRequest" | |
"Sec-Fetch-Dest" = "empty" | |
"Sec-Fetch-Mode" = "cors" | |
"Sec-Fetch-Site" = "same-origin" | |
"If-Modified-Since" = "Wed, 11 Oct 2023 15:24:53 GMT" | |
"If-None-Match" = "W/`"64ec791557fcd91:0`"" | |
} ` | |
-ContentType "application/json;charset=utf-8" -OutFile .\Alerts.json | |
$jsonData = Get-Content -Path ".\Alerts.json" -Raw -Encoding UTF8 | |
if($jsonData -ne $null) | |
{ | |
$jsonObject = ConvertFrom-Json $jsonData | |
} | |
if (($jsonObject.id -eq $jsonlast.id) -or ($jsonObject.id -eq $null)) | |
{ | |
if ($previous -ne "0"){ | |
write-host "no new alert" -ForegroundColor green | |
$previous = 0 | |
} | |
}else { | |
#if($jsonObject.data -like "*זיקים*"){ | |
# write-host "What you asked! Zikim" | |
$lastwrite = (gci .\Alerts.json).LastWriteTime | |
$b = $jsonObject.title | |
$b = $b.ToCharArray() | |
[array]::Reverse($b) | |
$b = -join($b) | |
write-host What happened: $b -ForegroundColor red | |
foreach ($item in $jsonObject.data) { | |
$c = $item | |
$c = $c.ToCharArray() | |
[array]::Reverse($c) | |
$c = -join($c) | |
write-host "Where: " $c -ForegroundColor red | |
} | |
write-host time: $lastwrite -ForegroundColor red | |
Write-Host " " | |
#[Console]::Beep(800, 1000); | |
#break | |
$previous = 1 | |
if($notification -ne $null){ | |
$notification.Dispose() | |
} | |
$notification = Show-BalloonNotification -Title $jsonObject.title -Text $jsonObject.data -DisplayDuration 300000 | |
} | |
#} | |
$jsonlast = $jsonObject | |
if($lastWrite -ne $null){ | |
$currentTime = Get-Date | |
$timeDifference = New-TimeSpan -Start $lastWrite -End $currentTime | |
if ($timeDifference.TotalMinutes -ge 5) { | |
$notification.Dispose() | |
$lastWrite = $null | |
#Write-Host "5 or more minutes have passed. Clearing old notifications" -ForegroundColor yellow | |
} | |
} | |
Start-Sleep -Milliseconds 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment