the-xkcd-community/the-red-spider-project — pull request #43 by whaatt (2013-07-03 23:04:55+00:00)
Title: IRC fortune command

This pull request adds a command, `fortune` (fortune.py), which randomly or specifically displays funny or witty IRC threads from #xkcd, using the XKCDB thread database. It also has the ability to locally access and cache these unconventional fortunes.

This also adds two optional dependencies, the `lxml` and `cssselect` libraries. The latter library was formerly included in the former, but in newer versions they have been split up into separate Python modules. Internet access is also optionally required, and all three dependencies need to exist to use the online database.

After installing `rsshell` with this program, the following command tests should run without error, unless there is invalid input entered, in which case an appropriate error message should be displayed to the user.

1. help can really be replaced with any invalid or nonexistent parameter
this should display help text for the other commands

fortune help (display help)
fortune asdf (display help)

2. this will notice that there's no cache file in the /work/fortune directory
and will create one using the example file in /other/fortune.txt
then it will display a random fortune from XKCDB and add it to cache

fortune (display random)

3. this is an alias of fortune used for accessing specific thread IDs
if you run it without a ID parameter, it is the same thing as fortune
if XKCDB is available, this will grab the desired thread, if it exists
if internet is not available, this will attempt to use the local cache

fortune fetch (display random)
fortune fetch 10000 (nonexistent ID)
fortune fetch 8175 (valid ID)
fortune fetch 1337 (valid ID, but isn't in cache)
fortune fetch asdf (invalid input)

4. this command can be used to manually create a cache file
without the pages parameter, 20 pages (50 threads per page)
will be downloaded into the cache file, /work/fortune.txt

fortune cache (cache 20 pages)
fortune cache 40 (cache 40 pages)
fortune cache asdf (display error)