Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter

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 https://twitter.com/statuses/friends_timeline.atom).Text
    $Entries = $Feed.feed.entry
    foreach ( $Entry in $Entries )
{
        $PublishTime = New-Object System.DateTime( $Entry.published.Substring(0,4),
        $Entry.published.Substring(5,2),
        $Entry.published.Substring(8,2),
        $Entry.published.Substring(11,2),
        $Entry.published.Substring(14,2),
        $Entry.published.Substring(17,2),
        [SYstem.DateTimeKind]::Utc
        )
        $CurrentContent += "($($PublishTime.ToLocalTime())) $($Entry.title)`n"
    }

    Compare-Object -referenceobject ($PreviousContent -split "`n" ) -differenceobject ( $CurrentContent -split "`n" ) | % {
        if ( $_.SideIndicator -eq "=>" )
{
            Send-IM -Server "im.flosoft.biz" -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: GeeksWithBlogs.net