-
Notifications
You must be signed in to change notification settings - Fork 0
/
UncommonSense.Asn.psm1
82 lines (70 loc) · 2.38 KB
/
UncommonSense.Asn.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function ConvertTo-DecimalOrNull
{
param
(
[Parameter(Mandatory, Position = 0)]
[string]$Value,
[ValidateNotNull()]
[CultureInfo]$FormatProvider = [cultureinfo]::GetCultureInfo('nl-NL')
)
[decimal]$Result = 0
switch ([decimal]::TryParse($Value, [System.Globalization.NumberStyles]::Currency, $FormatProvider, [ref]$Result ))
{
$true { return $Result }
$false { return $null }
}
}
<#
.SYNOPSIS
Retrieves ASN Bank investment fund prices
.EXAMPLE
Get-AsnFundPrice
#>
function Get-AsnFundPrice
{
param
(
)
$Document = ConvertTo-HtmlDocument -Uri https://www.asnbank.nl/beleggen/koersen.html
$Dates = $Document
| Select-HtmlNode -CssSelector '.fundrates thead tr th' -All
| ForEach-Object { $_.InnerText.Trim() }
| Where-Object { $_ }
| Select-Object -Skip 1
| ForEach-Object { [DateTime]::ParseExact($_, 'dd-MM-yyyy', $DutchCulture) }
$Cells = $Document | Select-HtmlNode -CssSelector '.fundrates tbody tr td' -All
0..($Cells.Length - 1) | ForEach-Object {
$CurrentIndex = $_
switch ($true)
{
($CurrentIndex % 4 -eq 0)
{
$CurrentFundProperties = [Ordered]@{}
$CurrentFundProperties.PSTypeName = 'UncommonSense.Asn.FundPrice'
$CurrentFundProperties.Fund = [System.Web.HttpUtility]::HtmlDecode($Cells[$CurrentIndex].InnerText)
break
}
($CurrentIndex % 4 -eq 1)
{
$CurrentFundProperties.Date = $Dates[0]
$CurrentFundProperties.Price = ConvertTo-DecimalOrNull -Value $Cells[$CurrentIndex].InnerText
[PSCustomObject]$CurrentFundProperties
break
}
($CurrentIndex % 4 -eq 2)
{
$CurrentFundProperties.Date = $Dates[1]
$CurrentFundProperties.Price = ConvertTo-DecimalOrNull -Value $Cells[$CurrentIndex].InnerText
[PSCustomObject]$CurrentFundProperties
break
}
($CurrentIndex % 4 -eq 3)
{
$CurrentFundProperties.Date = $Dates[2]
$CurrentFundProperties.Price = ConvertTo-DecimalOrNull -Value $Cells[$CurrentIndex].InnerText
[PSCustomObject]$CurrentFundProperties
break
}
}
}
}