Following twitter hashtags on TV

DSC06104As a lot of other people, I’m watching the debate of the Digital Economy Bill on BBC Parliament tonight. I’m also trying to follow along with some of the #debill back-channel on twitter.

With such a heated and interesting commentary on twitter, it reminded me of Roo’s “Second screen” idea of having tweets with a specific hashtag next to the TV during live TV events, when following the twitter backchannel during ‘The Apprentice’.

Unfortunately, I don’t have a spare laptop kicking around to show tweets on. But I do have a hackable TV. :-)

With that in mind, in just a few minutes I hacked together the following script to flash up tweets with the #debill tag on the TV:

# run me using:
#       python twittertv.py debill 1

import twython
import subprocess
import sys
from time import sleep

twitterKeyword = sys.argv[1]
twitterSearchRateLimitMins = int(sys.argv[2])

twitter = twython.core.setup()

showOnTVCommand = ['svdrpsend', 'mesg', 'messagetodisplay']

lasttweetid = 1

while True:
    search_results = twitter.searchTwitter(twitterKeyword, since_id=lasttweetid, show_user=True)

    numtweets = len(search_results["results"])
    for tweetnum in reversed(range(0, numtweets)):
        lasttweetid = search_results["results"][tweetnum]["id"]

        user = search_results["results"][tweetnum]["from_user"]
        tweet = search_results["results"][tweetnum]["text"]
        showOnTVCommand[2] = user + " : " + tweet

        subprocess.Popen(showOnTVCommand)
        sleep(20)

    sleep(twitterSearchRateLimitMins * 60)

DSC06127

It’s a quick-and-dirty hack, but I wanted to get something that would work before the debate was finished. :-)

And it seems to do the trick.

Tags: , , , ,

15 Responses to “Following twitter hashtags on TV”

  1. Ben Hardill says:

    Nice hack, here is a little tweak to the script to make it work with MythTV ;-)

    # run me using:
    #       python twittertv.py debill 1
    
    import twython
    import subprocess
    import sys
    from time import sleep
    
    twitterKeyword = sys.argv[1]
    twitterSearchRateLimitMins = int(sys.argv[2])
    
    twitter = twython.core.setup()
    
    showOnTVCommand = ['mythtvosd', '--template=alert', 'messagetodisplay']
    
    lasttweetid = 1
    
    while True:
        search_results = twitter.searchTwitter(twitterKeyword, since_id=lasttweetid, show_user=True)
    
        numtweets = len(search_results["results"])
        for tweetnum in reversed(range(0, numtweets)):
            lasttweetid = search_results["results"][tweetnum]["id"]
    
            user = search_results["results"][tweetnum]["from_user"]
            tweet = search_results["results"][tweetnum]["text"]
            showOnTVCommand[2] = "--alert_text=" + user + " : " + tweet
    
            subprocess.Popen(showOnTVCommand)
            sleep(20)
    
        sleep(twitterSearchRateLimitMins * 60)
  2. dale says:

    sweet – thanks! :-)

  3. […] Following twitter hashtags on TV (tags: twitter) […]

  4. Katherine says:

    Great! :) I couldn’t keep up with the tweeting they were coming in so fast. How fast would it have needed to run to cope with the 100 or so every 30 seconds which were streaming through last night?

    May I use your image of view of the empty House plus twitter feed in a ‘wrap up’ blpog post next Sunday?

  5. dale says:

    Katherine – The script will have missed some of the #debill tweets, but I didn’t really mind – not sure I could have read them all quick enough if it did get them all anyway! :-)

    Please feel free to use the image – bigger res version of it on flickr if that helps.

  6. dale says:

    Tony – thanks for the link – that looks brilliant!

  7. […] Following the Digital Economy bill with Twitter hashtags on TV >> dale laneIf you have a hackable TV…. being a Linux-based set-top box… and expertise in Python, you can give Parliament its own Twitterfall. […]

  8. […] Following the Digital Economy bill with Twitter hashtags on TV >> dale laneIf you have a hackable TV…. being a Linux-based set-top box… and expertise in Python, you can give Parliament its own Twitterfall. […]

  9. […] Following the Digital Economy bill with Twitter hashtags on TV >> dale laneIf you have a hackable TV…. being a Linux-based set-top box… and expertise in Python, you can give Parliament its own Twitterfall. […]

  10. Tom Morris says:

    Dale: are you using polling for this? Because you could quite easily use the live streaming API. It’s Ruby not Python, but here’s the code I use to pipe Twitter into IRC. It uses the TweetStream library in Ruby. There’s definitely something similar in Java and most likely there’s something similar in Python.

    http://github.com/tommorris/twittertoirc/blob/master/grabber.rb

  11. dale says:

    Thanks very much for that, Tom. I am polling, and that looks like it’d be a much better way of doing it. I’ll have to have a play with it.

  12. […] Last April, I wrote a quick-and-dirty Python script that displays tweets for a given hashtag on my TV screen so that I could follow the twitter backchannel about a programme that I […]

  13. […] Following the Digital Economy bill with Twitter hashtags on TV >> dale laneIf you have a hackable TV…. being a Linux-based set-top box… and expertise in Python, you can give Parliament its own Twitterfall. […]

  14. […] Some rights reservedA quick burst of links for you to chew over, as picked by the Technology teamFollowing the Digital Economy bill with Twitter hashtags on TV >> dale laneIf you have a hackable TV…. being a Linux-based set-top box… and expertise in Python, you can […]