-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-FplGameweek.ps1
62 lines (55 loc) · 1.63 KB
/
Get-FplGameweek.ps1
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
function Get-FplGameweek {
<#
.SYNOPSIS
Retrieves a list of FPL gameweeks
.DESCRIPTION
Retrieves a list of FPL gameweeks
.PARAMETER Gameweek
Retrieve a specific gameweek by it's number
.Parameter Current
Retrieves the current gameweek
.EXAMPLE
Get-FplGameweek
This will list all of the gameweeks
.EXAMPLE
Get-FplGameweek -Gameweek 14
This will list only gameweek 14
.EXAMPLE
9 | Get-FplGameweek
This will list only gameweek 9
.EXAMPLE
Get-FplGameweek -Current
This will list only the current gameweek
.LINK
https://psfpl.readthedocs.io/en/master/functions/Get-FplGameweek
.LINK
https://github.com/sk82jack/PSFPL/blob/master/PSFPL/Public/Get-FplGameweek.ps1
#>
[CmdletBinding(DefaultParameterSetName = 'Gameweek')]
param (
[Parameter(
ParameterSetName = 'Gameweek',
ValueFromPipeline
)]
[int]
$Gameweek,
[Parameter(ParameterSetName = 'Current')]
[switch]
$Current
)
$Response = Invoke-RestMethod -Uri 'https://fantasy.premierleague.com/api/bootstrap-static/' -UseBasicParsing
if ($Response -match 'The game is being updated.') {
Write-Warning 'The game is being updated. Please try again shortly.'
return
}
$Gameweeks = ConvertTo-FplObject -InputObject $Response.events -Type 'FplGameweek'
if ($Current) {
$Gameweeks.Where{$_.IsCurrent}
}
elseif ($Gameweek -gt 0) {
$Gameweeks.Where{$_.Gameweek -eq $Gameweek}
}
else {
$Gameweeks
}
}