Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New App Request] Bloomberg (On To Do List) #107

Open
AScott-WWF opened this issue Jul 16, 2024 · 0 comments
Open

[New App Request] Bloomberg (On To Do List) #107

AScott-WWF opened this issue Jul 16, 2024 · 0 comments

Comments

@AScott-WWF
Copy link

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)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant