Custom Twitter Ap Integration

While working at the Iowa Events Center I began writing a basic program to gather information published via twitter.  There were two main segments that we wanted to use.  We either wanted to the User_Timeline for the corporate twitter account, in this case @IAEventsCenter, or the second was for any special hashtag used by a concert or a show, i.e., #noshoesnationdm.

The idea would be to capture this information and parse it into a usable for format to display on the concourse TVs around the arena.  This would enable our marketing department to either post live information about current events to the screens or allow fans to send their messages and have them appear live on the screens.

To do this i started with the RSS feeds already generated by twitter.  The location of the information is

https://search.twitter.com/search.rss?q=%5c%22noshoesnationdm

The information in bold is what you would adjust to see different search results, the "noshoesnation" is the search data, the "%5%22" is the amount or type of data that it searches for

the results look like this



the data isn't real useful in this format beause it is cluttered with lots of extra characters and duplicated information, the only info I wanted was what is within the "Title" constraints.

To accomplish this, I modified an existing powershell script.

here is the link to the original file

http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Console-RSS-6cd37f06/view/Discussions

*.psm1


<#
.SYNOPSIS
    This module can be used to start a RSS ticker on your PowerShell console.
#>
Function Get-RSSFeed {
    <#
        .SYNOPSIS
            Retrieves an RSS feed from specified url.
         
        .DESCRIPTION
            Retrieves an RSS feed from specified url.
         
        .PARAMETER RSSUrl
            Url to pull RSS feed from.
         
        .NOTES
            Name: Get-RSSFeed
            Author: Boe Prox
            Created: 27JAN2012
            Modified: SCHMjDT
            Version: 2.0
                1.1 - Initial creation
     
        .EXAMPLE
            Get-RSSFeed -RSSurl 'https://search.twitter.com/search.rss?q=%5C%22noshoesnationdm'
         
            Description
            -----------
            Gets the Twitter title RSS feed.
    #>
    Param ($Rssurl='
https://search.twitter.com/search.rss?q=%5C%22noshoesnationdm')
    $Webclient = new-object net.webclient
    $Webclient.UseDefaultCredentials = $True
    $rss = [xml]$Webclient.DownloadString($Rssurl)
    $rss.rss.channel.item | ForEach {
        New-Object PSObject -Property @{
            Title = $_.Title
        }
    }
}
Function Start-RSSTitleTicker {
    <#
        .SYNOPSIS
            Starts the PowerShell Console Title ticker.
         
        .DESCRIPTION
            Starts the PowerShell Console Title ticker. Must be run from a PowerShell console!
         
        .PARAMETER RSSUrl
            Url to pull RSS feed from.
         
        .NOTES
            Name: Start-RSSTitleTicker
            Author: Boe Prox
            Created: 01JAN2013
            Modified: SCHMjDT
            Version: 2.0
                1.0 - Initial creation
     
        .EXAMPLE
            Start-RSSTitleTicker -RSSurl 'https://search.twitter.com/search.rss?q=%5C%22noshoesnationdm'
         
            Description
            -----------
            Gets the Twitter RSS feed and begins running display from PowerShell Console.
    #>
    Param ($Rssurl)
    #Configure Global Counter
    $Global:i=0
    Start-Job -Name RSS -ScriptBlock {
        Param ($Rssurl='http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss')
        While ($True) {
            $feed = Get-RSSFeed -Rssurl $Rssurl          
            Write-Output $feed
            #Wait
            Start-Sleep -seconds 180
        }
    } -ArgumentList $Rssurl -InitializationScript $GetRSSFeedsb | Out-Null
    #Update title for the initial run
    Start-Sleep -Seconds 5
    $Global:RSS = Receive-Job -Name RSS | Sort PublicationDate -Descending | Get-Unique -AsString |
    Select PublicationDate,Title,Link
    $host.ui.rawui.windowtitle = "{0} -- via PowerShell RSS" -f ($Rss[$i].Title)
 
    $timer = new-object timers.timer
    $action = {
            $i++  
            If ($i -lt ($Rss.count -1)) {
                $host.ui.rawui.WindowTitle = "{0} -- via PowerShell RSS" -f ($Rss[$i].Title)
            } Else {
                $Global:RSS = Receive-Job -Name RSS | Sort PublicationDate -Descending | Get-Unique -AsString |
                Select PublicationDate,Title,Link
                $i=0          
                $host.ui.rawui.WindowTitle = "{0} -- via PowerShell RSS" -f ($Rss[$i].Title)
            }
    }
    $timer.Interval = 20000 #20 seconds
    $Timer.Enabled=$True
    Register-ObjectEvent -InputObject $timer -EventName elapsed `
    –SourceIdentifier  RSSTimer -Action $action | Out-Null
 
    $Timer.Start()
}
<#
Add function into a scriptblock that can be re-used inside of a background job
This allows us to still use the Get-RSSFeed function outside of the job
#>
$GetRSSFeed = (Get-Command Get-RSSFeed).definition
$GetRSSFeedsb = [scriptblock]::Create(
    "Function Get-RSSFeed {$GetRSSFeed}"
)
Set-Alias -Name srt -Value Start-RSSTitleTicket
Set-Alias -Name grf -Value Get-RSSFeed
Export-ModuleMember -Function * -Alias *


Once the .psm1 file was modified and powershell was configured and loaded on each of the player machines there were only minor configuration changes that needed to be made, one was changing the exception rules on the workstations, another was altering the number of characters to allow in command prompt.  Because I was working with twitter, which has a predefined number of characters, this was any easy change.

*.ps1


import-module 'd:\media_installedcontent\twitter\twitter.psm1'   get-rssfeed -rssurl 'https://search.twitter.com/search.rss?q=%5C%22noshoesnationdm' >;d:\media_installedcontent\twitter\twitter.txt

I then created a batch file to reference a .ps1 file and run as a scheduled task

*.bat

      powershell.exe -file d:\media_installedcontent\twitter\twitter.ps1 > d:\media_installedcontent\twitter.txt.
Finally this outputted a .txt file in which each tweet was displayed by title only, one tweet per line and placed over the top of a custom background

Then the final project keeps the static background and rotates through the text overlay holding each message for 12 seconds.  The search parameters and the background are updated for each show







««««