-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGet-RoadmapData.ps1
93 lines (84 loc) · 2.92 KB
/
Get-RoadmapData.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#region Settings and variables
$dataFolder = 'data'
$versionFolder = Join-Path $dataFolder 'versions'
$roadmapRSSUri = 'https://www.microsoft.com/en-us/microsoft-365/RoadmapFeatureRSS/'
$timestamp = Get-Date -Format 'o'
#endregion Settings and variables
#region Functions
function ConvertRSSToFile {
param(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[Object]
$InputObject
)
process {
$matches = $null
$publicPreviewDate = $null
$GADate = $null
if ($InputObject.description -match '(?: *<br>Preview date: )([\w ]+)') {
$publicPreviewDate = $matches.1
$InputObject.description = $InputObject.description.Replace($matches.0, '')
}
if ($InputObject.description -match '(?: *<br>GA date: )([\w ]+)') {
$GADate = $matches.1
$InputObject.description = $InputObject.description.Replace($matches.0, '')
}
$objProperties = [ordered]@{
'guid' = $InputObject.guid.'#text'
'link' = $InputObject.link
'category' = $InputObject.category | Sort-Object
'title' = $InputObject.title
'description' = $InputObject.description
'pubDate' = $InputObject.pubDate
'updated' = $InputObject.updated
'publicDisclosureAvailabilityDate' = $GADate
'publicPreviewDate' = $publicPreviewDate
}
$processedObj = [PSCustomObject]$objProperties
ConvertTo-Json -InputObject $processedObj
}
}
#endregion Functions
#region Processing
Write-Host 'Script starting'
$res = Invoke-RestMethod $roadmapRSSUri
if (-not (Test-Path $dataFolder)) {
New-Item -ItemType Directory $dataFolder
Write-Host "Creating $dataFolder folder"
}
foreach ($entry in $res) {
<#
$entry = $res[0]
#>
# Generate filename
$fileName = $entry.guid.'#text'
$jsonEntry = $entry | ConvertRSSToFile
$outFilePath = Join-Path -Path $dataFolder -ChildPath "$fileName.json"
# Save previous version
$isNew = -not (Test-Path $outFilePath)
if (-not $isNew) {
$previousData = Get-Content $outFilePath | ConvertFrom-Json
}
# Save to file
$jsonEntry | Out-File -FilePath $outFilePath -Force
# Extract changes
$currentData = $jsonEntry | ConvertFrom-Json
if (Compare-Object $currentData.PSObject.Properties $previousData.PSObject.Properties) {
# If there are differences
$versionNumber = 0
$versionEntryFolder = Join-Path $versionFolder $fileName
if (-not (Test-Path $versionEntryFolder)) {
New-Item -ItemType Directory $versionEntryFolder
}
do {
$versionNumber++
$versionFile = Join-Path $versionEntryFolder "v$($versionNumber.ToString('0000')).json"
} until (-not (Test-Path $versionFile))
# Save differences to file
$fullContentObj = $currentData | Select-Object @{name="timestamp";expression={$timestamp}},*
$fullContentObj | ConvertTo-Json | Out-File $versionFile -Force
}
}
Write-Host 'Script finished'
#endregion Processing