mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-31 19:26:27 +02:00
Update check-moon-phase.ps1
This commit is contained in:
parent
751ab1c3a5
commit
ca0e597adc
@ -1,8 +1,8 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks the moon phase
|
||||
Checks the Moon phase
|
||||
.DESCRIPTION
|
||||
This script determines the moon phase and answers by text-to-speech (TTS).
|
||||
This script determines the Moon phase and answers by text-to-speech (TTS).
|
||||
.EXAMPLE
|
||||
PS> ./check-moon-phase
|
||||
.NOTES
|
||||
@ -12,23 +12,29 @@
|
||||
#>
|
||||
|
||||
try {
|
||||
$Day = (Invoke-WebRequest http://wttr.in/?format="%M" -UserAgent "curl" -useBasicParsing).Content
|
||||
if ($Day -eq "0") { $Reply = "Today is "
|
||||
} elseif ($Day -eq "1") { $Reply = "Yesterday was "
|
||||
} else { $Reply = "$Day days ago "
|
||||
$LunarCycle = 29.53058770576 # in days
|
||||
$LunarHalfCycle = $LunarCycle / 2.0
|
||||
$Phases = @("New moon", "Waxing crescent moon", "First quarter moon", "Waxing gibbous moon", "Full moon", "Waning gibbous moon", "Last quarter moon", "Waning crescent moon")
|
||||
$PhaseLength = $LunarCycle / 8.0
|
||||
$PhaseHalfLength = $PhaseLength / 2.0
|
||||
|
||||
$RefDate = get-date -Year 2021 -Month 12 -Day 4 -Hour 6 -Minute 43 # Dec 4, 2021 06:43 UTC [New Moon]
|
||||
$Now = get-date
|
||||
$TimeInterval = New-TimeSpan -Start $RefDate -End $Now
|
||||
$Days = $TimeInterval.TotalDays
|
||||
|
||||
$MDays = $Days % $LunarCycle
|
||||
$PhaseIndex = [int]($MDays * (8.0 / $LunarCycle))
|
||||
|
||||
$Visibility = [math]::Round((($Days % $LunarHalfCycle) * 100) / $LunarHalfCycle)
|
||||
$Reply = "$($Phases[$PhaseIndex]) with $($Visibility)% visibility"
|
||||
|
||||
$MoonAge = [math]::Round($Days % $LunarCycle)
|
||||
if ($MoonAge -eq "0") { $Reply += " today"
|
||||
} elseif ($MoonAge -eq "1") { $Reply += " since yesterday"
|
||||
} else { $Reply += ", last new moon was $MoonAge days ago"
|
||||
}
|
||||
|
||||
$Phase = (Invoke-WebRequest http://wttr.in/?format="%m" -UserAgent "curl" -useBasicParsing).Content
|
||||
if ($Phase -eq "🌑") { $Reply += "new moon"
|
||||
} elseif ($Phase -eq "🌒") { $Reply += "waxing crescent moon"
|
||||
} elseif ($Phase -eq "🌓") { $Reply += "first quarter moon"
|
||||
} elseif ($Phase -eq "🌔") { $Reply += "waxing gibbous moon"
|
||||
} elseif ($Phase -eq "🌕") { $Reply += "full moon"
|
||||
} elseif ($Phase -eq "🌖") { $Reply += "waning gibbous moon"
|
||||
} elseif ($Phase -eq "🌗") { $Reply += "last quarter moon"
|
||||
} elseif ($Phase -eq "🌘") { $Reply += "waning crescent moon"
|
||||
}
|
||||
$Reply += "."
|
||||
"✔️ $Reply"
|
||||
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
||||
exit 0 # success
|
||||
|
Loading…
Reference in New Issue
Block a user