Tag Archives: python

Latest tweets in your conky setup.

After getting a clean Ubuntu installation I decided to make few tweaks including a custom conky script which included a Twitter feed.

I made a quick research I found out the easiest solution using RSS feed is outdated so I have had to find the other way – and I did here.
As you can read there the only requirement is python-twitter package (and ofcourse python itself).

I have updated the code as it went obsolete when Twitter staff decided to complicate their API even more.

To make this script work you need a few of things:

1. Twitter account (duh)

2. Create Twitter application

3. Receive access tokens

After you will receive all required tokens you have to put them in marked place in the code below.

'''
Original author: Travis Moore (@travist120) from http://travist120.wordpress.com/
Updated by: Peter Kasperski (peter@kasperskiweb.pl) from http://kasperskiweb.pl
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see 
 
'''
import os
import string
import twitter
 
#set your API access details here.
consumer_key='CONSUMER KEY'
consumer_secret='CONSUMER SECRET'
access_token = 'ACCESS TOKEN'
access_token_secret = 'ACCESS TOKEN SECRET'
 
#how many tweets you want displayed at a time
twitterSize = 9;
 
#do not edit beyond this line.
api = twitter.Api(consumer_key, consumer_secret, access_token, access_token_secret)
status = api.GetFriendsTimeline()
i = 0
for s in status:
	i = i+1
	print s.user.name.encode("utf-8"), "(@"+s.user.screen_name.encode("utf-8")+"):"
 
	print s.text.encode("utf-8")
	print
	if i == twitterSize:
		break

The easy way to include it in your conky script is the following:

${execi 60 python ~/conky/scripts/twit.py | fold -w45}

If you will get any error try to run the script alone and make sure you have all required python libraries installed.