Let's Code! Bitcoin Price Notifier by Ben from 1 August 2020


So I am sure that all of you are as obsessed with bitcoin as I am lately? Right?

I am tired of constantly refreshing a browser window or my Cash App to see what the current price is. So I wrote a very simple notifier in powershell. I call this new script... Bitcoin Price Notifier. Gripping huh?

Every minute or so(you can totally change this timing) it goes out to the internet and gets the price of bitcoin. It then compares it to the price that it had previously. And since we are being lazy we don't want to just display that, no no, we want to hear it. It's better this way. We don't have to tab out of what we are doing. It just tells you that the price is either up or down, by how much, and what the current price is using a super sexy Microsoft Sam voice. Copy paste the code into a text editor and save it as a .ps1 file. Simply run this script by right clicking your new .ps1 file and selecting Run with Powershell. You could minimize the window or you could obsessively stair at the price updates... but I wouldn't. Now go about your life while getting soothing voice notifications about whether or not your money is burning up in server flames or building up into crypto millions.

Here is the code:


Add-Type -AssemblyName System.Speech
$Voice = New-Object System.Speech.Synthesis.SpeechSynthesizer

$Napalm = "https://millersecurityresearch.com/files/scripts/sounds/Napalm%20Death%20-%20You%20Suffer.mp3"
$Path = $Env:Temp + "\Napalm Death - You Suffer.mp3"
$Webclient = New-Object System.Net.WebClient
$Webclient.DownloadFile($Napalm, $Path)
Add-Type -AssemblyName presentationCore
$MediaPlayer = New-Object system.windows.media.mediaplayer
$MediaPlayer.open($Path)

$Response = Invoke-WebRequest -URI "https://api.coindesk.com/v1/bpi/currentprice.json" | ConvertFrom-Json
$StartingRate = $Response.bpi.USD.rate
Write-Host "Starting BTC: $StartingRate"

While (0 -lt 1){
    Start-Sleep -Seconds 60
    $Response = Invoke-WebRequest -URI "https://api.coindesk.com/v1/bpi/currentprice.json" | ConvertFrom-Json
    $CurrentRate = $Response.bpi.USD.rate
    If($StartingRate -gt $CurrentRate){
        $Difference = $StartingRate - $CurrentRate
        If($Difference -gt 25){
        $MediaPlayer.Play()
        }        
        $Voiceoutput = "Bitcoin Down by " + $Difference + " Dollars to " + $CurrentRate -replace ".{5}$"
        $Voice.Speak($Voiceoutput)
        Write-Host "Current BTC: $CurrentRate - Down"
    }
    If($StartingRate -lt $CurrentRate){
        $Difference = $StartingRate - $CurrentRate
        $Voiceoutput = "Bitcoin Up by" + $Difference + " Dollars to " + $CurrentRate -replace ".{5}$"
        $Voice.Speak($Voiceoutput)
        Write-Host "Current BTC: $CurrentRate - Up"
    }
    If($StartingRate -eq $CurrentRate){
        $VoicedRate = $CurrentRate -replace ".{5}$"
        $Voiceoutput = "Bitcoin same at " + $VoicedRate + " Dollars"
        $Voice.Speak($Voiceoutput)
        Write-Host "Current BTC: $CurrentRate"
    }
    $StartingRate = $CurrentRate
}