Skip to content

Instantly share code, notes, and snippets.

@soulemike
Created October 13, 2025 17:19
Show Gist options
  • Select an option

  • Save soulemike/63a80202b2fdf2fdc9bdf0aa8554c5fb to your computer and use it in GitHub Desktop.

Select an option

Save soulemike/63a80202b2fdf2fdc9bdf0aa8554c5fb to your computer and use it in GitHub Desktop.
For the provided list of LinkedIn activity URLs returns an array of hashtables, each containing the original activity URL, the HTML doc for the activity URL, the timestamp of the post, the post content, a shortened version of the post content, and an AI generated summary of the content.
$activities = @"
https://www.linkedin.com/feed/update/urn:li:activity:7383533745330618368
https://www.linkedin.com/feed/update/urn:li:activity:7383532739548979200
https://www.linkedin.com/posts/douglasfinke_ai-that-works-the-sf-unconference-is-under-activity-7383507297903206400-zvu0
"@
$activities = $activities.Split("`n")
$posts = @()
$regex = "[-:](?'id'[0-9]{19})[-\/?\$\s]"
#Install-Module psparsehtml, psai
Invoke-Expression $(Get-Secret -Name PSAI -AsPlainText)
Set-OAIProvider -Provider AzureOpenAI
Set-AzOAISecrets @secret
$prompt = "Provide a summary of no more than 10 words for the followng:"
foreach($activity in $activities){
$post = @{
activity = $activity
activityId = @{}
htmlDoc = Invoke-RestMethod $activity
postContent = ""
shortContent = ""
summary = ""
}
$postContentObject = ConvertFrom-Html -Content $post.htmlDoc
$post.postContent = $postContentObject.selectNodes('//article').selectNodes('//p')|Where-Object{
$_.Attributes.Name -eq "class" -and `
$_.Attributes.Value -like "*attributed-text-segment-list__content*"}
|Select-Object -First 1 -ExpandProperty InnerText
$activity
$post.shortContent = $post.postContent.Substring(0,[Math]::Min(200,$post.postContent.Length)-1)
$post.summary = Invoke-OAIChat "$prompt $($post.shortContent)"
$match = [Regex]::Match($activity,$regex)
$id = @{
decimal = ($match.Groups["id"]).Value
binary = ""
timestampBinary = ""
timestamp = ""
}
$id.binary = [Convert]::ToString($id.decimal,2)
$id.timestampBinary = $id.binary.Substring(0,41)
$id.timestamp = [DateTimeOffset]::FromUnixTimeMilliseconds([Convert]::ToInt64($id.timestampBinary,2)).DateTime
$post.activityId = $id
$posts += $post
}
@soulemike
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment