Last active
February 23, 2019 22:47
-
-
Save Windos/83b49044447ce8c156db017230274d52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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