Skip to content

Instantly share code, notes, and snippets.

@Windos Windos/BlogTweet-Azure.ps1
Last active Feb 23, 2019

Embed
What would you like to do?
$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
You can’t perform that action at this time.