Skip to content

Instantly share code, notes, and snippets.

@johnallers
Last active November 13, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnallers/178576f097a8a7986fcb17a92c88a486 to your computer and use it in GitHub Desktop.
Save johnallers/178576f097a8a7986fcb17a92c88a486 to your computer and use it in GitHub Desktop.
#Run this every 1/2 hour and in an 8 hour work day there will be approximately 3 times per day that your victim hears a cat fact
if ((Get-Random -Maximum 10000) -lt 1875) {
Add-Type -AssemblyName System.Speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri 'http://catfacts-api.appspot.com/api/facts')).facts
$SpeechSynth.Speak("did you know?")
$SpeechSynth.Speak($CatFact)
}
@benjaminlukeclark
Copy link

That API seems to be kaput sadly ;n;

I get the following error:

Invoke-WebRequest : Python 2.5 is no longer available. Please refer to https://goo.gl/aESk5L for more information

But I found another API that works and wacked that into your script...

#Run this every 1/2 hour and in an 8 hour work day there will be approximately 3 times per day that your victim hears a cat fact
if ((Get-Random -Maximum 10000) -lt 1875) {
Add-Type -AssemblyName System.Speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$Random = Get-Random -Maximum 200
$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri http://www.catfact.info/api/v1/facts.json?per_page=200)).Facts[$Random]
$SpeechSynth.Speak("did you know?")
$SpeechSynth.Speak($CatFact.details)
}

This is such a novel idea I love it. I'm going to include it in my PowerShell course I'm teaching to try and get the old curiosity peaked.

@mitch-j
Copy link

mitch-j commented Dec 17, 2018

Both APIs are now out. So here's the script with another API that seems to work for now:

#Run this every 1/2 hour and in an 8 hour work day there will be approximately 3 times per day that your victim hears a cat fact
if ((Get-Random -Maximum 10000) -lt 1875) {
Add-Type -AssemblyName System.Speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$Random = Get-Random -Maximum 200
$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri https://catfact.ninja/fact))
$SpeechSynth.Speak("did you know?")
$SpeechSynth.Speak($CatFact.fact)
}

@dmissp
Copy link

dmissp commented Nov 13, 2019

Wrote an on-demand function for the fun of it.

function get-catfact {
    param (
        [switch]$say
    )
     [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
    
    $catfact = (convertfrom-json (Invoke-WebRequest -UseBasicParsing -Uri https://catfact.ninja/fact)).fact

    if ($say){
    Add-Type -AssemblyName System.Speech
    $global:SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $global:SpeechSynth.Speak("did you know?")
    $global:SpeechSynth.Speak($CatFact)
    } else {
        $catfact
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment