Bash function to post to Twitter via command line

Mar 25, 2009 15 Replies

####################################################### Twitter # Usage: # # Twitter I am eating sushi right now # Twitter() { local USERNAME=myusername local PASSWORD=mypassword



# Verify that you have URI::Escape perl module. if perl -MURI::Escape -e exit; then true else echo "perl Module URI::Escape missing. You need to install it." 1>&2 return 1 fi



MESSAGE=$(echo -n "$@" | perl -MURI::Escape -ne 'print uri_escape( $_ )')



COMMAND="curl --basic --user $USERNAME:$PASSWORD --data-ascii status=$MESSAGE

formatting link
" $COMMAND > /dev/null 2>&1 && echo Success. }


Now I know why they call it twit (ter) ;)

status=$MESSAGE

formatting link
"> $COMMAND > /dev/null 2>&1 && echo Success.

Nice and simple -- but I would have added a test to make sure that the username and password had been set to something other than the defaults you have in there. Or perhaps able to read them from a file like ~/.twitter/accountname so you could use it for mutiple accounts by typing "twitter junque I am eating sushi right now" and it would read the username and password for account "junque" before proceeding.

Now -- all I need to do is to create a twitter account -- and find people who are interested enough in my day-to-day minutiae to read it. :-)

Thanks, DoN.

status=$MESSAGE

formatting link
">> $COMMAND > /dev/null 2>&1 && echo Success.

This is what I do, I have a file ~/.../.../twitter.txt with username and password. It is secret. My family shares my .bashrc, so I cannot have my twitter password there (which is unique and is not used on any other website), but I have it in a secret file.

Well, when posting your minutiae is as easy as typing something on command line, you may reconsider.

[ ... ]

O.K. That will work.

That deals with the ease part, but I can't imagine that anybody is interested in what I just ate. Now for metalworking perhaps, but I would rather do the work than type about it like that. (And when I *do* describe it, it tends to be too many characters for twitter to accept.

I don't think that I would follow *anyone* here's tweets. I don't *care* what anybody has for breakfast, and for the things which I

*do* care about -- I would want more detail than would be practical.

Enjoy, DoN.

Well, it is up to you as to what you post. I am not sure myself if I want to use it or not. But, I would imagine that twittering about a big project in progress is kind of fun to follow, frmo the rec.crafts.metalworking perspective.

(...)

-- and

We've been here all along, DoN.

--Winston

Say you have a dicey medical exam today and the whole family wants to know about the results. A few tweets as things progress and everybody (your family members) knows what's happening.

You're at a job site and you don't have the proper part on your truck. One tweet alerts all fellow coworkers about what you need and where you are located. Who ever has it and is close by can respond...

Most of what I see Twitter being used for so far is pretty worthless.

You haven't been *exposed* to my day-to-day minutiae. :-)

"Cat boarded lap. Kneaded cat's tummy for half an hour. Cat got bored."

Enjoy, DoN.

O.K. That would work -- if they knew about the twitter account to start with. Remember -- all of my siblings are now old farts, and I'm the techno-geek of the family. :-)

Hmmm ... about all these workers visiting twitter all day. Not sure about that. (Unless there is a way to set it up to call all their cell phones when you tweet.)

That or beyond it. :-)

Enjoy, DoN.

Same problem here, the other parties don't even have a computer...

There is a cell phone interface/application for it I understand. I don't know how it works though, no cell phone to play with and I don't know anyone with a cell geeky enough to try it.

The cell phone part (depending upon how it works) is the only practical side to it I can see. It (Twitter) could create a nice bridge between the two very different worlds (computer to cell phone).

You are supposed to use the walkie talkie function on your blackberry for that. Use the right technology for crying sakes. I'm going to have to route you to detention. ;)

Wes

-- We are living in the society that Ayn Rand warned us about in 1957.

When Nextel first came online in my area (~1997) with their "Push to Talk" mantra a lot of contractors switched over, replacing their two-way radios. When their first months billing hit they went ballistic. Unit-to-unit was included, one to all was an extra charge. Some of the guys had racked up bills around $500 between that and their extra phone minutes.

That would be a refreshing change from say, half the postings I read! :)

--Winston

James Waldby wrote: (...)

Heh! Cool!

Hmm. How can I use this...

--Winston

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required