[New App Request] Bloomberg (On To Do List)
AScott-WWF opened this issue · 0 comments
AScott-WWF commented
This is one more from the To Do list.
This will return all executables from the Bloomberg Software Updates page (https://www.bloomberg.com/professional/support/customer-support/software-updates/), then remove any duplicate entries (based on the Download URL).
I have had to construct a new format for the Version so that files which contain contiguous 8 digits within their name are converted from what looks like a date of release in MMDDYYYY to MM.DD.YYYY format.
FYI: These "versions" match the Release Date shown on the site.
N.B. This also makes use of the ReleaseDate Parameter introduced in the [Enhancement] Microsoft SSMS
Script:
# Get-Bloomberg.ps1
# Define AppName
$AppName = "Bloomberg"
# Main script to fetch and process links
$ReleaseUrl = "https://www.bloomberg.com/professional/support/customer-support/software-updates/"
Write-Verbose "Obtaining $($AppName) Windows release versions from $($ReleaseUrl)...`n"
# Download the HTML content of the page to a string
$htmlContent = (Invoke-WebRequest -Uri $ReleaseUrl).Content
# Define the regex pattern to match all rows containing .exe downloads
$rowPattern = '(?s)<tr id="download-[^"]*">(?:(?!<tr id="download-).)*?href="[^"]+\.exe".*?</tr>'
# Define the regex pattern to extract the product name, release date, and download URL
$dataPattern = '(?s)<td class="name"( colspan="2")?>(?<ProductName>[^<]+).*?<td class="date">(?<ReleaseDate>[^<]*)</td>.*?href="(?<Uri>[^"]+\.exe)"'
# Initialize an array to store the extracted data
$AppVersions = @()
# Find all the rows with .exe downloads
$rows = [regex]::Matches($htmlContent, $rowPattern)
# Extract the product name, release date, and download URL from each row
foreach ($Row in $Rows) {
$match = [regex]::Match($Row.Value, $dataPattern)
if ($match.Success) {
if ($match.Groups["ProductName"].Value -Match '64-Bit') {
$Arch = 'x64'
} elseif ($match.Groups["ProductName"].Value -Match '32-Bit') {
$Arch = 'x86'
} else {
$Arch = 'Multi'
}
$AppVersions += [PSCustomObject]@{
ProductName = $match.Groups["ProductName"].Value.Trim()
ReleaseDate = $match.Groups["ReleaseDate"].Value.Trim()
DownloadUrl = $match.Groups["Uri"].Value.Trim()
Architecture = $Arch
}
}
}
# Remove duplicates based on the DownloadUrl, then Sort by ProductName
$AppVersions = $AppVersions | Sort-Object -Property DownloadUrl -Unique | Sort-Object -Property ProductName
foreach ($AppVersion in $AppVersions) {
$SearchCount = 1 # This may need increasing as future versions are released
#Build each link with File Type specific versions
$URL = $($AppVersion.DownloadUrl)
if ($URL -match '\d{8}') {
#Write-Verbose "URL: $url contains an 8-digit number."
$number = $matches[0]
# Split the 8-digit number (Release Date) into the required format (xx.xx.xxxx)
[version]$Version = "{0}.{1}.{2}" -f $number.Substring(0, 2), $number.Substring(2, 2), $number.Substring(4, 4)
} else {
[version]$Version = Get-Version -String $URL -ReplaceWithDot
}
do {
if ($URL) {
New-NevergreenApp -Name "$($AppName) - $($AppVersion.ProductName)" -Version $Version -ReleaseDate $($AppVersion.ReleaseDate) -Uri $URL -Type "EXE" -Architecture $($AppVersion.Architecture)
break
}
$SearchCount--
} until ($SearchCount -eq 0)
if ($SearchCount -eq 0) {
Write-Warning "Could not find release for $($AppName) $($AppVersion.Type)"
}
}
$ReleaseNotesUrl = "https://www.bloomberg.com/professional/support/release-notes/"
Write-Verbose "$($AppName) Release notes are available here: $($ReleaseNotesUrl)"