Thursday, April 09, 2009

The first CONKY TWITTER CLIENT ZOMG!


Well, I can't really say that it's the first conky twitter client. Any twitter client from cli should be able to work. But I can say that this is something that I am very proud of it because I MADE IT!!!

In order to get this on your sexy conky configuration, you are going to have to jump through some hoops. So bear with me.

First up is to install python-twitter.

sudo apt-get install python-twitter

Now that wasn't so bad was it?

Now we are going to have to edit your conky configuration.

put "text_buffer_size 10000" (no quotes) into your ~.conkyrc file. This allows conky to display more text than normally. Make sure that it goes before TEXT.

now download the script, or copy and paste for your enjoyment.
'''This piece o' junk hack of python and twitter was created by
Travis Moore (@travist120). Some 17 year old kid who decided that he
was severely bored one day and decided to create this instead of doing
his Essay and french homework.
'''





'''Oh, and the licence. I have to make sure that those who copy will give back.'''

'''
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
.

'''

for s in status:
i = i+1
print s.user.name, "(@"+s.user.screen_name+")"
print s.text
print
import os
import string
import twitter
#set your user name and password here.
username=''
password=''

api = twitter.Api(username, password)
status = api.GetFriendsTimeline()
#how many tweets you want displayed at a time
twitterSize = 5;
i = 0 if i == twitterSize:
break


Make sure that if you copy and paste it, you name it cwitter.py.

Now to make it show up in conky.

${execi 60 python ~cwitter.py | fold -w45}

stick that under your TEXT and you are done. I have set the time (60 seconds) as default because it's nice and safe on Twitter's servers. Feel free to change that.

-w45 might also need to be changed. This is the word wrap settings, so you are going to have to manually figure that one out by trial and error.


Posted via web from travist120's posterous

13 comments:

castlecraver said...

Travis:
Dunno if you mis-copypasta'd it, but it looks like things are kinda out of order here? I made an implementation entirely based on yours that's a little cleaner (albeit uncommented).Also note that I'm running it in Jaunty and MD5 as imported by twitter (why?) is now deprecated, so you have to add the lines to ignore deprecation warnings before importing twitter, if you want it to show up nicely in Conky. This seems to get the job done, no idea how it'll hold up in the future. Hopefully someone updates twitter. I'm pretty new at this, just replacing the import in twitter f's stuff up, and I don't have the knowledge to really fix it.

Travis said...

Actually, you were right. I did miscopy pasta, and I only updated my Posterous account with the correction.

I found out an even better way to print

print "%s (@%s):" % (s.user.name, s.user.screen_name)

At least, that is how I remember. I'm very new to python, so new that I don't understand what was changed :D lol

Travis said...

Actually, you were right. I did miscopy pasta, and I only updated my Posterous account with the correction.

I found out an even better way to print

print "%s (@%s):" % (s.user.name, s.user.screen_name)

At least, that is how I remember. I'm very new to python, so new that I don't understand what was changed :D lol

thyeum said...

Travis:
I just starting using your script and it seems that when someone puts a parenthesis in their tweet it breaks the script. Here's the error message I get:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 10: ordinal not in range(128)
any suggestions? thanks.

Travis said...

Looks like Python is getting upset about paranthesis being stored in strings. I'll see if there is an escape character for it. Or if I could have it scan the string and replace it with the escaped parenthesis. Although, I never had this problem myself. I'll test it just to be sure.

Travis said...

Oh quick correction, I pasted the code incorrectly.

It should be like this:

import os
import string
import twitter
#set your user name and password here.
username=''
password=''

api = twitter.Api(username, password)
status = api.GetFriendsTimeline()
#how many tweets you want displayed at a time
twitterSize = 5;
i = 0
for s in status:
i = i+1
print s.user.name, "(@"+s.user.screen_name+")"
print s.text
print
if i == twitterSize:
break

thyeum said...

alright, seems to work fine now.
thanks for the upate.

the blog said...

File "/home/someone/scripts/cwitter.py", line 17
for s in status;
^
SyntaxError: invalid syntax

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

Anonymous said...

I just discovered the website who reviews about
Several
home business opportunity

If you want to know more here it is
home business opportunity
www.home-businessreviews.com

Anonymous said...

I just discovered the website who discuss about
many
home based business reviews

If you want to know more here it is
home based business
www.home-businessreviews.com

swagat said...

hi, probably your code is outdated? just a doubt. it seems twitter API now requires OAuth authentication. the twitter.Api('username', 'password') doesn't work now?

Anonymous said...

Yeah, the code is out-dated. Twitter has changed it so that only 'official' twitter apps have access now, if I recall correctly.