mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-29 16:16:47 +01:00
Improve list-exchange-rates.ps1
This commit is contained in:
parent
53bd5ec1cc
commit
8318ba58c3
@ -14,44 +14,19 @@
|
|||||||
|
|
||||||
param([string]$currency = "USD")
|
param([string]$currency = "USD")
|
||||||
|
|
||||||
function WriteBar { param([string]$Text, [float]$Value, [float]$Max)
|
function ListExchangeRates { param([string]$currency)
|
||||||
$Num = $Value
|
[xml]$ExchangeRates = (invoke-webRequest -uri "http://www.floatrates.com/daily/$($currency).xml" -userAgent "curl" -useBasicParsing).Content
|
||||||
if ($Num -gt $Max) { $Num = $Max }
|
foreach($Row in $ExchangeRates.channel.item) {
|
||||||
$Num = ($Num * 70.0) / $Max
|
new-object PSObject -property @{ 'Rate' = "$($Row.exchangeRate)"; 'Currency' = "$($Row.targetCurrency) - $($Row.targetName)"; 'Inverse' = "$($Row.inverseRate)"; 'Date' = "$($Row.pubDate)" }
|
||||||
while ($Num -ge 1.0) {
|
|
||||||
write-host -noNewLine "█"
|
|
||||||
$Num -= 1.0
|
|
||||||
}
|
}
|
||||||
if ($Num -ge 0.875) {
|
|
||||||
write-host -noNewLine "▉"
|
|
||||||
} elseif ($Num -ge 0.75) {
|
|
||||||
write-host -noNewLine "▊"
|
|
||||||
} elseif ($Num -ge 0.625) {
|
|
||||||
write-host -noNewLine "▋"
|
|
||||||
} elseif ($Num -ge 0.5) {
|
|
||||||
write-host -noNewLine "▌"
|
|
||||||
} elseif ($Num -ge 0.375) {
|
|
||||||
write-host -noNewLine "▍"
|
|
||||||
} elseif ($Num -ge 0.25) {
|
|
||||||
write-host -noNewLine "▎"
|
|
||||||
} elseif ($Num -ge 0.125) {
|
|
||||||
write-host -noNewLine "▏"
|
|
||||||
}
|
|
||||||
write-host " $Value $Text"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
" Exchange Rates Today for 1 $currency"
|
|
||||||
" =============================="
|
|
||||||
" Source: http://www.floatrates.com"
|
|
||||||
""
|
""
|
||||||
|
"Exchange Rates Today for 1 $currency (source: http://www.floatrates.com)"
|
||||||
|
"=================================================================="
|
||||||
|
|
||||||
[xml]$ExchangeRates = (invoke-webRequest -uri "http://www.floatrates.com/daily/$($currency).xml" -userAgent "curl" -useBasicParsing).Content
|
ListExchangeRates $currency | format-table -property Rate,Currency,Inverse,Date
|
||||||
foreach($Row in $ExchangeRates.channel.item) {
|
|
||||||
[string]$Name = $Row.targetName
|
|
||||||
[float]$Value = $Row.exchangeRate
|
|
||||||
WriteBar $Name $Value 10.0
|
|
||||||
}
|
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user