Olympics: a db-driven command-line application
Folder: olympics (same folder as for your database design assignment!)
Tag: olympics-cli
You will work alone on this assignment. Feel free to discuss it with classmates, but submit your own work.
Goal
- Learn to use the psycopg2 module to access your PostgreSQL databases from within Python programs.
Rubric
1 - author names in comment at top of olympics.py
2 - olympics.sql is present and populates your database successfully
via "psql -U MY_POSTGRES_USER_NAME olympics < olympics.sql"
1 - help/usage statement appears and is descriptive
4 - required program features are present and work correctly
4 - code organization and quality, based on all our discussions
of such issues so far this term (commenting, the code reviews,
"high quality routines", etc.)
Things to do
- You did the psycopg2 lab, right?
- Make sure your database/olympics-schema.sql file is up to date with respect to your actual olympics database.
Save a copy of your olympics database using this Unix command:
pg_dump --no-owner --no-privileges -U YOUR_PG_USER olympics > olympics.sqlThis will be a moderately big file (probably somewhere between 10MB and 40MB, depending on your database design), but that's OK. (Do note, however, that GitHub imposes file-size limits, so watch out for that.) This operation (putting olympics.sql into your repo) will make it possible for the grader to grade your assignment.
Write a Python command-line program named olympics.py that enables the user to do the following:
- Print a usage statement for "python3 olympics.py -h" (or --help). You may use argparse or not for command-line parsing and usage statement printing.
- List the names of all the athletes from a specified NOC.
- List all the NOCs and the number of gold medals they have won, in decreasing order of the number of gold medals.
- One more operation of your choosing. Simple is fine, crazily-ambitious is also fine. (Both are worth the same number of points, though crazily-ambitious may earn you more points on the Cosmic Scoreboard. Or fewer. I have no idea how the cosmos keeps score.)