Fortune and cowsay on Windows, roll out your own in Python

I have recently created a series of video tutorials in which I explain how to create an analog of fortune and cowsay for Windows.

The software is written in Python (so it is actually cross platform), the tutorials are entry level. If you have some basic ideas about programming, you should not have problems figuring out what is going on.

My primary objective is to use it as an aid in teaching. It would be wonderful if more of my students used Python, so I hope I can point them to the videos and expose them to the beauty of the language.

There are a few analogs of fortune for Windows, but they are graphical applications that display the text in a separate window; whereas I want the messages to be shown in the console automatically.

There is also a cowsay equivalent, but I figured that since it is rather easy to make a simplified alternative of my own - I'd just use it as an excuse to create a few more screencasts.

The covered subjects:

Yes, if you look well enough, you can find existing versions of these programs that run on Windows. But a screencast about running two programs is not as cool as one about creating your own, right? :-)

Have fun watching and feel free to ask questions. Here's the intro (don't forget to switch to HD quality):

Find a site with quotes we can harvest

XPath experiments and query examples

Python and LXML, examples of XPath queries with Python

Automate page retrieving via HTTP and HTML parsing with lxml

Python and SQLite

Joining the building blocks, finally we can harvest all the quotes

ASCII art experiments, listing directories and reading files with Python

Fixing the graphical artifacts in the ASCII art

Integrating the program into Windows' command line interpreter, cmd.exe

Prettifying the text with Python's textwrap module

If you speak Russian, you may find this set of tutorials interesting - Python - как автоматичеси собирать информацию с сайтов.

Comments

Constantin — 2012-02-01 09:57

Cool! Do you know about ipython? It is an alternative Python shell with tons of nifty features. Here is a good starting point: http://ipython.org/ipython-doc/stable/interactive/tutorial.html I looked for a video showing off the best features, but I didn’t find one. Maybe I’ll make one :P

gr8dude — 2012-02-01 16:28

I do. I use bPython on Linux, but on Windows I usually rely on PyScripter - which is an awesome IDE (free, open source, lightweight).

I remember setting it up once but there was something that didn’t go well, but I can’t recall what it was.

If you make that video - I’m definitely checking it out :-)