This Time Self-Hosted
dark mode light mode Search

Bored, so… fortune-mod!

It’s 5am and I haven’t slept yet.. my life is feeling kinda fuzzy lately, and I haven’t been able to produce much good for Gentoo either, which is something that usually cheers me up. Hopefully now that Klothos (the Ultra5) is operative, I can do something to fix that kldload bug.

Tonight being totally bored, I’ve decided to proceed with one of my evil plans, this time, not one of those involving Ciaran (feel free to look up the reference by yourself).

After watching Voyager, I was thinking that it was too bad there wasn’t a fortune-mod-startrek package, or at least I tried to look for it and the only thing I found is a “Ferengi rules of acquisition” package from FreeBSD ports (that we miss, dammit we need to add it to portage or we’ll never beat ports…). IMDB has a neat page full of Voyager quotes and teh definitive answer would be to make a simple script to fetch those and transforming them in a fortune file..

I never used AWK in my life, it has been (and it still is) one of the Unix utilities obscure to me, but I knew the few bits needed to produce the following function:

imdb2fortune() {
    awk '/</a>/, /(||]+>/, ""); print; } ' 
        "$1" | 
    sed -e '/([%:]$|^ *[.*] *$)/! s:^:t:' -e 's:":":g' | 
    fmt -s -w 72 | 
    sed -e '/^[ rt]*$/d' | 
     > "$2"

I know it’s not exactly clean, that there are two calls to sed, and probably some of that stuff could have done directly inside awk, but considering I never used it, I’m pretty satisfied with the results.

I’ve tried it locally, and I was able to get fortune datafiles for Star Trek: Voyager, Star Trek: Nemesis and Friends, which is kinda good for a script wrote in half an hour without having slept all the night….

I must say, one of my favourite quotes is for sure this one:

Janeway: Jean-Luc, how would you like a trip to Romulus?
Picard: With or without the rest of the fleet?

Comments 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.