This website was originally written in Ruby and hosted on the Raspberry Pi. It's now archived at GitHub for posterity!

Clockatoo Twitter Feed

With text displaying on the Clockatoo, albeit poorly, there was one thing I couldn't resist doing; grabbing the latest tweets and displaying them on the 4-digit, 7-segment display as a sort of Raspberry-Pi-Buzz-Eye-Catchy-Notification-Thing.

After putting together a hacky abomination involving Ruby's "t" Gem, a Python script to push its stdin to the 7-segment display and a kludge of a shell script that runs the former through "sed" before piping it into the latter, I started writing this post. Upon realising the sheer insanity of this solution, I searched for a more graceful one and found it in Tweepy.

Before we go any further, you should head on over to https://dev.twitter.com/apps, log in with your Twitter account ( or a new one specifically for this kind of tinkering ), create an App and set it up for read access.

Tweepy is, as you might have guessed, a Python library facilitating Twitter access. It's not as easy to get set up as "t", which includes a step-by-step process for authentication. You're in luck, however; I've done all the tricky OAuth nonsense and wrapped it up in a handy script you can use:

#!/usr/bin/python

import tweepy

print 'You must create a new application at dev.twitter.com'
print 'Once you have done this, find the secret/key under details'

consumer_key	= raw_input("Enter your consumer key: ")
consumer_secret = raw_input("Enter your consumer secret: ")

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)

print 'Please enter this URL into your browser and follow the instructions:'
print auth.get_authorization_url()

access_token = raw_input("Enter your access token ( PIN ): ")

auth.get_access_token(access_token)

print 'Your authentication details (save these!):'
print 'key:    ' + auth.access_token.key
print 'secret: ' + auth.access_token.secret

After you've installed tweepy, grab this script and run it to set up your OAuth access. The profoundly lazy can:

$ pip install tweepy
$ wget https://pi.gadgetoid.com/tweepy-setup && chmod +x tweepy-setup && ./tweepy-setup

Once you've got OAuth set up, the world of Twitter is your oyster. This is the script I used to get my timeline onto the 7-segment display:

#!/usr/bin/python

import tweepy

consumer_key 	= "YOUR CONSUMER KEY HERE"
consumer_secret = "YOUR CONSUMER SECRET HERE"

access_key	 	= "YOUR ACCESS KEY HERE"
access_secret	= "YOUR ACCESS SECRET HERE"

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_key,access_secret)

api = tweepy.API(auth)

home_timeline = api.home_timeline()

import sys

# This should be the path to my Geekroo-Product-Clockatoo fork
# Be sure to use the right RX.0 folder for your Pi revision
# Find the fork at: https://github.com/Gadgetoid/Geekroo-Product-Clockatoo
sys.path.append('../Geekroo-Product-Clockatoo/R2.0')

from Raspi_7Segment import SevenSegment

segment = SevenSegment(address=0x70)

# Display all tweets in your home_timeline on the 7 seg display
for tweet in home_timeline:
	print("Displaying text: " + tweet.text)
	segment.writeTextString(tweet.text)

Once again, the lazy can:

$ wget https://pi.gadgetoid.com/tweepy && chmod +x tweepy

Be sure to edit in your application details and authentication details!

Once you're set up, you can simply type ./tweepy and your twitter feed should appear on your Clockatoo board! Bear in mind that each post will take about 30 seconds to display. You can tweak the script to display faster or slower as necessary, but consider limiting the number of tweets you display and their frequency if you want it to be readable!

« Back to index Posted on 2013-04-30 by