Out of Sorts, take 4
September 2016 updates: major-league Python code tidying (and new data listings).
Having, erm, sorted out book list sorting back in January 1989 (on my Amstrad CP/M PC), and, a year later book list sorting (under Acorn RISC OS), how about some really modern book list sorting, undertaken with the help of a SQLite DB and some adroit Python snake charming? On a 64-bit Linux Mint system?
I've been teased...
... by Brian for my Luddite approach to data file handling. He advocates Python for text field handling... basically. For the last umpty1 years I've kept ASCII data files of my books, videos, and music. Until 1994, I would occasionally print these out as jolly nice DTP catalogues that the print room staff in the basement of IBM Hursley house were happy to copy, collate, and bind for me in return for small-scale financial inducements, a few good jokes, or just some of my more scandalous gossip.
What happened in 1994? Basically, the web.
Since the books I'd been writing in IBM all used a markup language, HTML was just another set of tags to handle. With less paper2 to print. So my book lists lived on in cyberspace. With the block and column edit facilities of the TextPad editor on Windows I would sort them by Author, by Title, by Genre, by price, by date of purchase... and then whack them in between a pair of <pre> and </pre> tags, with a bit of HTML / CSS wrappering, letting the web browser do the work. Tab-separated data. What could be easier?
"Why do it that way?" asked Brian, horrified at the thought of treating data in such a haphazard, cavalier way. (He was too polite to say "amateurish", but I've known him long enough to know that's what he thought. And he's right.) "Show me a better way", said I. He did.
I now have a SQLite DB that I can enter data directly into, or load from an ASCII data file by Python code. Further code extracts, sorts, and formats the data (with some CSS assistance from me). It handles all the special cases of authors whose names contain accents, or who insist on a surname beginning with a lowercase3 letter, or book titles similarly afflicted. The generated web pages are indistinguishable from the hand-crafted horrors I've laboriously produced for two decades. But with one crucial difference. These web pages take mere seconds of CPU time to generate. Plus a bit of typing at a command prompt. Using TextPad on Windows, it could take me an hour or more to prepare the same4 files.
See how they run!
A recent example, run on 24th September, 2016 on Skylark: