Skip to content

Instantly share code, notes, and snippets.

@CrookedJ
Last active May 26, 2025 13:57
Show Gist options
  • Save CrookedJ/bd6652345457aba53be0489a2d834201 to your computer and use it in GitHub Desktop.
Save CrookedJ/bd6652345457aba53be0489a2d834201 to your computer and use it in GitHub Desktop.
Get-ConnectionsHint.ps1
# Fetches category hints from Mashable for the NYT Connections game.
function Get-ConnectionsHint {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[string]$Number = ([int](New-TimeSpan -Start '2023-09-20' -End (Get-Date)).Days + 101),
[switch]$Categories
)
$lookupDate = ConnectionsNumberToDate $Number
$urlbase = 'https://mashable.com/article/nyt-connections-hint-answer-today-'
$url = '{0}{1}' -f $urlbase, $lookupDate
$req = Invoke-WebRequest -Uri $url -UseBasicParsing
$content = $req.Content -split '\n' | Where-Object { $_ -match 'Yellow:' } | Select-Object -Skip 1 -First 2
$pattern = '<li><p>Yellow:.*?<strong>(.+?)</strong></p></li><li><p>Green:.*?<strong>(.+?)</strong></p></li><li><p>Blue:.*?<strong>(.+?)</strong></p></li><li><p>Purple:.*?<strong>(.+?)</strong></p></li>'
if ($Categories) {
$content[1] -match $pattern | Out-Null
}
else {
$content[0] -match $pattern | Out-Null
}
[pscustomobject]@{
Date = $lookupDate
Number = $Number
Yellow = $matches[1]
Green = $matches[2]
Blue = $matches[3]
Purple = $matches[4]
}
$debugOut = @{
Url = $url
Number = $Number
Categories = $Categories
Content = $content
}
Write-Debug "Debug Output: $($debugOut | ConvertTo-Json)"
}
function ConnectionsNumberToDate {
[CmdletBinding()]
param (
[Parameter(Mandatory,
Position = 0)]
[ValidateRange(101, 1000)]
[int]$Number
)
# First one available is 101 on 2023-09-20
(Get-Date '2023-09-20').AddDays($Number - 101) |
Get-Date -Format 'MMMM-d-yyyy'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment