Subject: New Hack: Unix Fortunes as XML

From: Shlomi Fish <[email-masked]>
Date: Wed, 14 May 2008 20:39:06 +0300

Hi all!

I originally outlined a grand-unified vision for a quotes sharing site here:

http://www.shlomifish.org/philosophy/ideas/fortunes-mania/

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 
fortune cookies:

http://www.shlomifish.org/humour/fortunes/

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 
them.

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 
information.

You can see the results in pages such as:

* http://www.shlomifish.org/humour/fortunes/shlomif-fav.html

* http://www.shlomifish.org/humour/fortunes/tinic.html

And there are also the XMLs such as:

http://www.shlomifish.org/humour/fortunes/shlomif-fav.xml

(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:

http://svn.berlios.de/svnroot/repos/web-cpan/XML-Grammar-Fortune/trunk/

Note that at the moment, it segfaults on perl-5.10.0, due to this bug which I 
reported:

http://rt.cpan.org/Public/Bug/Display.html?id=35781

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.

Regards,

	Shlomi Fish

-----------------------------------------------------------------
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.