the-xkcd-community / the-red-spider-project

Coding and xkcd combined, for fun!
http://the-xkcd-community.github.com/the-red-spider-project
Other
40 stars 33 forks source link

IRC fortune command #43

Closed whaatt closed 11 years ago

whaatt commented 11 years ago

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)
jgonggrijp commented 11 years ago

Looks good. At what platform(s) did you test this? How would you suggest testing the program on the remaining platforms? Consider #30 for an elaborate example.

whaatt commented 11 years ago

Thanks for the pointer; I think something similar should work for installing my fork and the command. As of now, I've only tested on Windows, since I don't have a Linux box handy, but I'll fire up a VM later and try it if no one else wants to give it a shot. Same situation for any other platforms.

1. cd $RED_SPIDER_ROOT        (for testing on Linux)
   cd %RED_SPIDER_ROOT%       (for testing on Windows)

2. # add me on git 
   git remote add whaatt git://github.com/whaatt/the-red-spider-project.git

3. git fetch whaatt
   git checkout whaatt/fortune

4. ./setup.py                 (for Linux)
   setup.py                   (for Windows)

5. rsshell

6. # now, attempt the tests from above
   # if everything goes as planned...

7. exit
jgonggrijp commented 11 years ago

I now see that your first post already mentioned testing. Sorry for not reading thorough enough on the previous occasion!

jgonggrijp commented 11 years ago

OK, I tested this on OS X 10.8.4 with Python 2.7 and it worked like a charm. Sorry for making you wait for so long. I think in this case we have enough reason to trust that it'll also work on Linux so I'll just go ahead and merge this little perl.

Quote 8175 is a really good by the way!