Updated list-coffee-prices.ps1

This commit is contained in:
Markus Fleschutz 2024-05-14 16:18:13 +02:00
parent 411756abc6
commit 3721feeaa9

View File

@ -5,6 +5,10 @@
This PowerShell script queries alphavantage.co and lists the global price of coffee (monthly, in cents per points). This PowerShell script queries alphavantage.co and lists the global price of coffee (monthly, in cents per points).
.EXAMPLE .EXAMPLE
PS> ./list-coffee-prices.ps1 PS> ./list-coffee-prices.ps1
Monthly Global Price of Coffee (by alphavantage.co, in cents per pound)
-----------------------------------------------------------------------
2024-04-01 240
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -29,22 +33,23 @@ function WriteHorizontalBar { param([float]$Value, [float]$Max)
} elseif ($Num -ge 0.125) { } elseif ($Num -ge 0.125) {
Write-Host "" -noNewline Write-Host "" -noNewline
} }
Write-Host " $Value" Write-Host " $Value" -noNewline
} }
try { try {
Write-Progress "Loading data from www.alphavantage.co..." Write-Progress "Loading data from www.alphavantage.co..."
$prices = (Invoke-WebRequest -URI "https://www.alphavantage.co/query?function=COFFEE&interval=monthly&apikey=demo" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json $prices = (Invoke-WebRequest -URI "https://www.alphavantage.co/query?function=COFFEE&interval=monthly&apikey=demo" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
Write-Progress -completed " " Write-Progress -completed "Done."
"" ""
"$($prices.name) (by alphavantage.co, in $($prices.unit))" "Monthly $($prices.name) (by alphavantage.co, in $($prices.unit))"
"---------------------------------------------------------------" "-----------------------------------------------------------------------"
foreach($item in $prices.data) { foreach($item in $prices.data) {
if ($Item.value -eq ".") { continue } if ($Item.value -eq ".") { continue }
Write-Host "$($item.date) " -noNewline Write-Host "$($item.date) " -noNewline
[int]$value = $Item.value [int]$value = $Item.value
WriteHorizontalBar $value 350.0 WriteHorizontalBar $value 350.0
Write-Host "ct"
} }
exit 0 # success exit 0 # success
} catch { } catch {