View Single Post
03-22-2007   #31 (permalink)
divigation
Concierge
 
divigation's Avatar
 
Join Date: Dec 2006
Location: Houston
Posts: 768
divigation is on a distinguished road
Send a message via AIM to divigation Send a message via Skype™ to divigation
So getting rather annoyed with Twitterific and Twitter Post not working, I decided to dive into messing with the Twitter API via Terminal to see if I couldn't bypass the apps. For simply posting to Twitter via the command line:

$curl -u username:password --form status="Message text here." http://twitter.com/statuses/update.xml

And voila, your message is posted. Although it takes a while because Twitter's server sucks and can't handle the traffic of its popularity. As for reading posts, I am still trying to get that correct, but I don't know enough programming to write a good script to output exactly what I would like, so at current I am running the following in GeekTool and having it post on my desktop, refreshing every minute (or at least a minute after the two or three minutes it takes to fetch the data from Twitter's crappy server). So here is the code:

$curl -u username:password http://twitter.com/statuses/friends_timeline.xml|grep "<text>\|<relative_created_at>\|<name>"

The possible fields you can choose to display are:
<created_at> standard time stamp instead of relative that I am using
<screen_name> screen name instead of full name that I am using
<location> user's location
<description> user's description of self
<profile_image_url> the profile image, good if you were going to use this to write an actual app, useless for the command line
<url> user's homepage

Additionally, you can check 3 other lists rather than the Friends and You timeline:
http://twitter.com/statuses/public_timeline.xml
http://twitter.com/statuses/friends.xml
http://twitter.com/statuses/followers.xml
The first is obviously the public timeline, the second and third show a list of each of your friends (or followers) and their last post with the same tags as the timelines. If you have growlnotify installed, you could then pipe whatever feed into a growl notification, but you would want to modify your grep to grab the first instance or the first two, rather than spitting out your whole list (-m3 after grep to tell it to print three lines).

Anyhow, I am trying to clean this up so that I can get a solid output, though after a few minutes the tags just disappear to my eyes. although if you are running this in Terminal, rather than GeekTool, you can add --color=always between grep and the patterns and the tags will show up bold and red, making it easy to look past them. Hopefully there will be other feedback on cleaning this up and simplifying it. Of course adding an alias to your .profile for whatever command you want to use would be greatly useful. twitter is now my command for checking my timeline feed.

It is ridiculous that I wasted time today messing with this! Perhaps posting all of the information here somehow justifies it a bit.

_________________________

So thanks to Equin I have here is the code to clean out the tags

sed -e :a -e 's/<[^>]*>//g;/</N;//ba'

So the line I am now refreshing in GeekTool is:

$curl -u username:password http://twitter.com/statuses/friends_timeline.xml|grep "<text>\|<relative_created_at>\|<name>"|sed -e :a -e 's/<[^>]*>//g;/</N;//ba'

The result is a clean string of text, a thing of beauty! Then utilizing GeekTool I also have a similar string which is then piped into growlnotify every five minutes, giving me the last post every five minutes. Between the desktop and the growl reminders I am able to stay on top of my friends posts without any problems.
__________________
17" MBP 2.33GHz C2D 3GB RAM 160GB HDD
TV [courtesy of the fine folks at TAB] & iPhone

Last edited by divigation; 03-22-2007 at 09:04 PM. Reason: Updated info thanks to Equin's command of Unix
divigation is offline   Reply With Quote