Geeks With Blogs

Lance's TextBox

Mark Schill was another of the winners of the PowerScripting Podcast’s NetCmdlets scripting contest.

Mark submitted a tweet-im script, which sends an instant message about new tweets found in the Twitter RSS feed.  They explained on the podcast that Twitter used to have an IM-bot feature which went away, so Mark created this script himself to meet this need.  The script simply sits and fetches your Twitter friends timeline feed every x seconds, checks to see if the items it finds are newer than the last check, and if so sends out an IM (jabber/xmpp) containing the content of the tweet.

Here is Mark’s script:

# Here is a script that interrogates the Twitter RSS feed and sends an IM for each posting. 
# It starts out with all of the postings in the feed and then posts each subsequent posting as it is added.
# Author: Mark Schill

$TwitterUsername = "user"
$TwitterPassword = "password"

$IMServer = "server"
$IMRecipient = "recipient"
$IMCredential = get-credential

$ThisPath = $MyInvocation.MyCommand.Path | split-path
$TempFile = "$ThisPath\twitterstatus.txt"

$PreviousContent = ""

while ($TRUE)
    $CurrentContent = ""
    [xml]$Feed = (Get-HTTP -user $TwitterUsername -password $TwitterPassword
    $Entries = $Feed.feed.entry
    foreach ( $Entry in $Entries )
        $PublishTime = New-Object System.DateTime( $Entry.published.Substring(0,4),
        $CurrentContent += "($($PublishTime.ToLocalTime())) $($Entry.title)`n"

    Compare-Object -referenceobject ($PreviousContent -split "`n" ) -differenceobject ( $CurrentContent -split "`n" ) | % {
        if ( $_.SideIndicator -eq "=>" )
            Send-IM -Server "" -Credential $IMCredential -Recipient $IMRecipient -Message $_.InputObject
            Write-Host $_.InputObject

    $PreviousContent = $CurrentContent
    #Sleep for 5 minutes
    Start-Sleep 60
Technorati Tags: ,
Posted on Thursday, September 11, 2008 10:56 AM PowerShell | Back to top

Comments on this post: PowerShell: tweet-im

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Lance Robinson | Powered by: