The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Wednesday, July 18, 2007

Stupid Twitter Tricks

An off-site meeting was canceled, although I didn't find out about it until I got off-site. Afterwards, I slacked off a bit.

Okay, quite a bit.

I came across this post on one of the blogs I follow, and I was mesmerized. Not by the the actual post but by the often times totally irrellevent picture John Wiseman adds to his posts. And in this case, it's a portion of a screen capture of a Twitter-based site, and John's comment about said picture: “Jenny Holzer is the only person who should be allowed to use Twitter.” Jenny's site reads like surreal fortune cookies, much like the monster quote file I have (over 2,600 quotes).

I've seen Twitter once or twice; enough to get the point of it—it's LiveJournal on crank, but something about Jenny's site reminding me of my own monster quote file inspired me to do a “Stupid Twitter Trick™”—sending out my quote file via Twitter.

Two aspects of this little hack (and that's what it is, a gross hack if you ask me) were time consuming. First, cleaning up my monster quote file. Twitter limits you to 160-character messages (with a preference of 140 characters). Three custom programs for this—one to pull out quotes 160 characters or less (and to mark the 140th character). The second one to trim unwanted spaces. And the third to go through converting the quote character from the unappealing " to the much more typographically nice “” pair. Extensive use of sed to make some other typographical substitutions (such as converting “--” (two dashes) into “—” (a proper em-dash)) and a visual once-over to make sure I didn't muck things up, and an hour or so later, I have almost 2,000 quotes ready for Twitter.

The second time-consuming bit was writing this bit of code, which took about an hour:

#!/usr/bin/perl
use strict;
use Net::Twitter;

my $later   = `./later`;
my $message = `./quote -n`;
my $twit    = Net::Twitter->new(
	username => 'siwisdom' , 
	password => 'XXXXXXXXXXXX');
my $result  = $twit->update($message);

`at -f ./at-jobs $later`;

exit 0;

And no, it didn't take an hour because I'm a slow typist. It took an hour because to install Net::Twitter I needed to install JSON::Any, and in the process of installing that I apparently activated the CPAN module that wanted to install and update itself, and that took an hour (I swear, it seemed to download the entire CPAN archive—sigh).

The later program picks a random amount of time between three and nine hours, which is given to the at command. at is like cron, in that you can schedule a program to run at a particular time, but unlike cron, which runs the program on a set schedule, at is a one-shot deal. I use at because I don't want a set schedule to post quotes to Twitter—I want it randomized a bit. quote is a program I wrote ages ago to pull quotes out of a quote file sequentially.

Like I said, a quick hack for a stupid Twitter trick.

Oh, and the name? “siwisdom”?

It's short for “silicon wisdom,” as a pun on Jorn Barger's Robot Wisdom, if you will.

Obligatory Picture

[I'm wearing a goatee—I must be my evil twin brother.]

Obligatory Links

Obligatory Miscellaneous

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: http://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

http://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2014 by Sean Conner. All Rights Reserved.

Listed on BlogShares