Update list-coffee-prices.ps1

This commit is contained in:
Markus Fleschutz 2023-05-26 12:34:08 +02:00
parent 1cd755a378
commit 75f7212595

View File

@ -11,24 +11,23 @@
Author: Markus Fleschutz | License: CC0
#>
function WriteBar { param([string]$Text, [float]$Value, [float]$Max)
Write-Host "$Text " -noNewline
function WriteHorizontalBar { param([float]$Value, [float]$Max)
$Num = ($Value * 100.0) / $Max
while ($Num -ge 1.0) { Write-Host "" -noNewline; $Num -= 1.0 }
if ($Num -ge 0.875) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.75) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.625) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.5) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.375) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.25) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
} elseif ($Num -ge 0.125) {
Write-Host -noNewLine ""
Write-Host "" -noNewline
}
Write-Host " $Value"
}
@ -40,9 +39,9 @@ try {
"---------------------------------------------------------------"
foreach($item in $prices.data) {
if ($Item.value -eq ".") { continue }
[string]$date = $item.date
Write-Host "$($item.date) " -noNewline
[int]$value = $Item.value
WriteBar $date $value 300.0
WriteHorizontalBar $value 350.0
}
exit 0 # success
} catch {