CS 257: Software Design

Books: command-line arguments and CSV

Folder name: books

I updated this assignment on Monday, 9/21 in the afternoon. It was confusing to me (let alone to anybody else) as originally written. Changes are in red.

I'll assign you a new random team on Friday, 9/18. This weekend, read the assigned article, and think about features and command-line syntax before your Discussion Group #1 meeting next week (Monday or Tuesday). You can certainly start coding, but recognize that we won't finalize your command-line syntax until your DG#1 meeting.

Goals

The data: books, authors, and comma-separated values

Take a look at books.csv, a file full of data about books and authors. There are only a couple dozen books in this dataset, so you wouldn't want to base an important book-related application on it. But for learning about how to manipulate datasets like this, a couple dozen books will be plenty.

The format of books.csv is known as comma-separated values (CSV). CSV is a very simple format used to store tables of textual data. Each line of text represents a row in the table, and the fields/columns in each row are separated by commas. These few lines illustrate the principle: "title,publication year,author"

Jane Eyre,1847,Charlotte Brontë (1816-1855) To Say Nothing of the Dog,1997,Connie Willis (1945-) The Stone Sky,2017,N.K. Jemisin (1972-)

The only thing that makes CSV at all tricky is when the data in one of the table cells contains either a comma or a newline character. For example, consider the novel "Right Ho, Jeeves" by P.G. Wodehouse. If you just comma-separate the fields, you get this:

Right Ho, Jeeves,1934,Pelham Grenville Wodehouse (1881-1975)

which will make software misinterpret " Jeeves" as the second column of this row, instead of the tail end of the first column. CSV solves this problem with quotation marks:

"Right Ho, Jeeves",1934,Pelham Grenville Wodehouse (1881-1975)

But of course now you have the question of what happens if the title of your book includes quotation marks. You should read up on how CSV handles these situations.

For this and possibly future assignments, you'll be using the books.csv file as your database. Your programs will read data from this file as needed to satisfy the requirements of the assignment. To do this, you'll use Python's csv module.

Command-line arguments in Python

Writing programs that use command-line arguments to determine their behavior is an important skill. In my day-to-day life as a programmer, I write a lot of short programs (and some long ones) to do all manner of tasks for me. Sometimes in very very short programs that I plan to run exactly once, I'll hard-code input values into the program. Those programs are often like: "Open file something.txt, read its contents, do something with the contents, and print out the results". In cases like this, I'll often just put the "something.txt" right in the code.

But even when I expect to run a program only once, I generally have to run it a few times during debugging, and then I often find that it's more useful than I thought, and I end up running it on multiple different input files, sometimes sorting the output one way, other times sorting the output another way, and so on. In such cases, I always wish I had taken one or two minutes to set up a sensible command-line argument syntax for the program.

For this assignment, you are going to write a command-line tool for extracting information from the books dataset. The assignment will have two phases. First, you will design a command-line interface for the tool. Then, after revising your design based on feedback from your discussion group, you will implement the resulting interface.

The details

What features should your program have?

You can easily imagine many features appropriate for a command-line tool concerned with a books-and-authors dataset. We're going to restrict our work to the following features:

What you need to do

  1. Select one partner's cs257-assignments-USERNAME git repository to work in. Make sure all partners are given access to the repository, and that all partners have a local clone.
  2. Create a folder called "books" at the top level of the repository. (Note the very top of this web page, where I have the notation "Folder name: books". For future assignments, you should use that "Folder name" indicator to store your work for the assignment. This is how the grader and I will find your work.)
  3. By 11:59 Tuesday, 9/22: Design your tool's command-line syntax, and write a usage/help statement for it. Put your usage statement in books/usage.txt. Add, commit, and push this so I can see it in your repositories.
  4. By 5:00 Friday, 9/25: Implement your tool's features, making sure to adhere to the command-line syntax you described in usage.txt. Make sure that your program prints a Usage statement (e.g. by printing the contents of usage.txt) if the users request it (via a suitable help flag) or if what they typed doesn't satisfy your expected command-line syntax.

Phase 1: design your tool's command-line syntax

  • Write a short list of features ("short" as in 2-3 features) that you want the tool to have. (For example, "print out the list of all authors whose names contain a specified string" or "print out a list of books by the author with the specified name", etc.)
  • Create a Unix-manual-page-style statement of your tool's command-line syntax. Your proposed syntax should support the features you listed in the previous item.
  • Be ready to paste your feature list and your command-line syntax into a Google doc at your discussion group meeting on either 9/21 or 9/22.

Phase 2: revise your command-line syntax based on discussion-group feedback, and implement the resulting features. Make sure that your program prints a Usage statement if the users request it (via a suitable help flag) or if what they typed doesn't satisfy your expected command-line syntax. Due 5:00PM 9/25.

Constraints and suggestions

Start early, ask questions, and have fun!

(And don't forget Slack—our #questions channel is meant for you!)