Skip to content

Instantly share code, notes, and snippets.

@Windos
Last active February 23, 2019 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/83b49044447ce8c156db017230274d52 to your computer and use it in GitHub Desktop.
Save Windos/83b49044447ce8c156db017230274d52 to your computer and use it in GitHub Desktop.
$Uri = 'https://king.geek.nz/rss/'
$Posts = [System.Collections.ArrayList]::new()
$PageNumber = 1
$More = $true
while ($More) {
try {
$Page = Invoke-RestMethod -Uri "$Uri$PageNumber" -ErrorAction Stop
} catch {
$Page = $null
}
if ($Page.Count -gt 0) {
foreach ($Post in $Page) {
$null = $Posts.Add($Post)
}
$PageNumber += 1
} else {
$More = $false
}
}
$PostToPost = $Posts | Get-Random
$Title = $PostToPost.title.'#cdata-section'
$Excerpt = $PostToPost.description.'#cdata-section'
$Link = $PostToPost.link
$Categories = $PostToPost.category | foreach {$_.'#cdata-section'.replace(' ', '')}
$Hashtags = ''
foreach ($Category in $Categories) {
$Hashtags += " #$Category"
}
$TweetText = "From the blog archive: ""$Title""`n`n$Excerpt$Hashtags`n$link"
try {
Import-Module -Path .\Modules\PSTwitterAPI\PSTwitterAPI.psd1
} catch {
Write-Warning 'Import-Module complained about the Path argument.'
}
$OAuthSettings = @{
ApiKey = $env:TWITTER_APIKEY
ApiSecret = $env:TWITTER_APISECRET
AccessToken = $env:TWITTER_ACCESSTOKEN
AccessTokenSecret = $env:TWITTER_ACCESSTOKENSECRET
}
Set-TwitterOAuthSettings @OAuthSettings
Send-TwitterStatuses_Update -Status $TweetText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment