2024-01-25 13:37:12 +01:00
|
|
|
Script: *list-coffee-prices.ps1*
|
|
|
|
========================
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
list-coffee-prices.ps1
|
|
|
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2023-05-26 12:20:18 +02:00
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
List coffee prices
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script queries alphavantage.co and lists the global price of coffee (monthly, in cents per points).
|
|
|
|
.EXAMPLE
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./list-coffee-prices.ps1
|
2024-05-19 10:25:56 +02:00
|
|
|
|
|
|
|
Monthly Global Price of Coffee (by alphavantage.co, in cents per pound)
|
|
|
|
-----------------------------------------------------------------------
|
|
|
|
2024-04-01 ████████████████████████████████████████████████████████████████████▌ 240
|
2023-05-26 12:20:18 +02:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
2023-07-29 09:45:37 +02:00
|
|
|
function WriteHorizontalBar { param([float]$Value, [float]$Max)
|
2023-05-26 12:20:18 +02:00
|
|
|
$Num = ($Value * 100.0) / $Max
|
|
|
|
while ($Num -ge 1.0) { Write-Host "█" -noNewline; $Num -= 1.0 }
|
|
|
|
if ($Num -ge 0.875) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▉" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.75) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▊" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.625) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▋" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.5) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▌" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.375) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▍" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.25) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▎" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
} elseif ($Num -ge 0.125) {
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "▏" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
2024-05-19 10:25:56 +02:00
|
|
|
Write-Host " $Value" -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-12-07 20:24:45 +01:00
|
|
|
Write-Progress "Loading data from www.alphavantage.co..."
|
2023-05-26 12:20:18 +02:00
|
|
|
$prices = (Invoke-WebRequest -URI "https://www.alphavantage.co/query?function=COFFEE&interval=monthly&apikey=demo" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
|
2024-05-19 10:25:56 +02:00
|
|
|
Write-Progress -completed "Done."
|
2023-09-20 17:05:11 +02:00
|
|
|
|
2023-05-26 12:20:18 +02:00
|
|
|
""
|
2024-05-19 10:25:56 +02:00
|
|
|
"Monthly $($prices.name) (by alphavantage.co, in $($prices.unit))"
|
|
|
|
"-----------------------------------------------------------------------"
|
2023-05-26 12:20:18 +02:00
|
|
|
foreach($item in $prices.data) {
|
|
|
|
if ($Item.value -eq ".") { continue }
|
2023-07-29 09:45:37 +02:00
|
|
|
Write-Host "$($item.date) " -noNewline
|
2023-05-26 12:20:18 +02:00
|
|
|
[int]$value = $Item.value
|
2023-07-29 09:45:37 +02:00
|
|
|
WriteHorizontalBar $value 350.0
|
2024-05-19 10:25:56 +02:00
|
|
|
Write-Host "ct"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of list-coffee-prices.ps1 as of 08/15/2024 09:50:49)*
|