Created
November 4, 2014 07:26
-
-
Save dfch/d5990fdb391fe1b84b76 to your computer and use it in GitHub Desktop.
[NoBrainer] PowerShell Currency Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://d-fens.ch/2014/01/07/nobrainer-powershell-currency-converter/ | |
| Param ( | |
| [Parameter(Mandatory = $true, Position = 0)] | |
| [string] $From | |
| , | |
| [Parameter(Mandatory = $true, Position = 1)] | |
| [string] $To | |
| , | |
| [Parameter(Mandatory = $false, Position = 2)] | |
| [Alias("Amount")] | |
| [double] $Value = 1 | |
| , | |
| [Parameter(Mandatory = $false, Position = 3)] | |
| [Alias("When")] | |
| [DateTime] $Date = [datetime]::Now | |
| ) # Param | |
| $UrlTemplate = 'http://www.oanda.com/currency/converter/update?base_currency_0={0}"e_currency={1}&end_date={2}&view=details&id=1&action=C&'; | |
| [Uri] $Url = $UrlTemplate -f $From, $To, $Date.ToString('yyyy-MM-dd'); | |
| $r = Invoke-RestMethod -Uri $Url; | |
| if($PSBoundParameters.ContainsKey('Value')) { | |
| ($r.data.bid_ask_data | gm -Type Properties).Name | % { $r.data.bid_ask_data.$_ *= $Value; }; | |
| for($c = 0; $c -lt $r.data.chart_data.Count; $c++) { $r.data.chart_data[$c][-1] *= $Value; }; | |
| } # if | |
| $Currency = [Ordered] @{}; | |
| ($r.data.bid_ask_data | gm -Type Properties).Name | % { $Currency.Add($_, $r.data.bid_ask_data.$_); }; | |
| # for($c = 0; $c -lt $r.data.chart_data.Count; $c++) { | |
| # $dt = New-Object Datetime($r.data.chart_data[$c][0], $r.data.chart_data[$c][1], $r.data.chart_data[$c][2]); | |
| # $Currency.Add($dt.ToString('yyyy-MM-dd'), $r.data.chart_data[$c][-1]); | |
| # } # for | |
| return $Currency; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment