New Hack: Unix Fortunes as XML
- Hi all!
I originally outlined a grand-unified vision for a quotes sharing site here:
This is a very nice vision, but also something that I found very intimidating
to implement. So I didn't. :-)
Instead, what I did was continue to add text fortunes to the collection of my
Now, as I noted, one problem in this scheme, was that to refer someone to a
certain fortune, I needed to give him the link to the plain text file and
then say "search for Perl". Not good. And it was still a plaintext file that
wasn't linked to the rest of the site.
Now, anvari.org has put some fortunes (including mine) on
http://www.anvari.org/fortune/ . He used an SQL database to store them as
plaintext, and link to them. However, he doesn't have id's and the links are
the first sentence.
So I decided to:
1. Create an XML grammar for storing fortunes (with some extra meta-data like
an ID, a title, etc.)
2. Convert the fortunes to this XML.
3. XMLise them a bit.
4. Publish them on my site as XHTML after using an XSLT stylesheet to convert
So I started defining a very basic grammar, a rudimentary XSLT stylesheet and
wrote a Perl script to convert them, and then added id="", title="", and more
You can see the results in pages such as:
And there are also the XMLs such as:
(I didn't define an XSLT or CSS stylesheet for the XMLs for the time being,
though it shouldn't be hard.)
The XML grammar is still very limited - it only supports <irc> fortunes (for
IRC conversation logs) or <raw> fortunes (for a gigantic <pre>). But it's a
start - Rome wasn't built in a day, and Linux reportedly started as a
non-glorified 386-only terminal emulator.
You can find the code for the stylesheets here:
Note that at the moment, it segfaults on perl-5.10.0, due to this bug which I
Plans for the future include:
1. Define more types of fortunes - quotes, screenplays, etc.
2. Convert my existing fortunes to them.
3. Create a bridge to RSS/Atom to syndicate the new fortunes as news.
4. Add more meta-data for the fortunes.
5. Write a Perl module to translate the fortunes back to text. (Not sure if
XSLT is up to the task.)
In the future, this might end up as a more serious attempt to create a
(structured - not free form), open, sharing and syndication site for quotes.
Comments are welcome.
Shlomi Fish http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html
The bad thing about hardware is that it sometimes work and sometimes doesn't.
The good thing about software is that it's consistent: it always does not
work, and it always does not work in exactly the same way.