mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-08 09:20:19 +02:00
Update check-moon-phase.ps1
This commit is contained in:
parent
751ab1c3a5
commit
ca0e597adc
@ -1,8 +1,8 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks the moon phase
|
Checks the Moon phase
|
||||||
.DESCRIPTION
|
.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
|
.EXAMPLE
|
||||||
PS> ./check-moon-phase
|
PS> ./check-moon-phase
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -12,23 +12,29 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Day = (Invoke-WebRequest http://wttr.in/?format="%M" -UserAgent "curl" -useBasicParsing).Content
|
$LunarCycle = 29.53058770576 # in days
|
||||||
if ($Day -eq "0") { $Reply = "Today is "
|
$LunarHalfCycle = $LunarCycle / 2.0
|
||||||
} elseif ($Day -eq "1") { $Reply = "Yesterday was "
|
$Phases = @("New moon", "Waxing crescent moon", "First quarter moon", "Waxing gibbous moon", "Full moon", "Waning gibbous moon", "Last quarter moon", "Waning crescent moon")
|
||||||
} else { $Reply = "$Day days ago "
|
$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"
|
"✔️ $Reply"
|
||||||
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
Loading…
Reference in New Issue
Block a user