Internals of the weblog script

Two files contain the code for this script:

The run script

Overall, the script has these steps:

  1. Read our database file, weblog_db, containing the usage data from previous days. This database is represented as a WebAccessDB object (see weblog.py for the definition of this class). The WebAccessDB object is stored in variable db.

    If this is the first run of the script, the database file doesn't exist yet. If it doesn't (we determine this by using os.path.exists()), we call the WebAccessDB constructor with a value of None for the file name, which causes it to return an empty WebAccessDB object.

    The logic for this step is contained in function openDatabase().

  2. Read the new log entries from the standard input stream, adding them to the database object db.

    This step corresponds to function addLog().

  3. Write the database back out to the file. This is subroutine writeDatabase.

  4. Write three web pages into directory /u/www/docs/tcc/webstats/. The first page is homepage.html and shows the time range and the total on- and off-campus accesses. This page is pretty short. The other two pages are byurl.html, which lists all accesses alphabetized by URL, and byhits.html, showing the same data but sorted in descending order of number of hits.

    The logic for this step is in function writeWeb().

Objects for the weblog application: weblog.py

The weblog.py module contains three classes used by the weblog application.