def track(filename, logFile=accessLog):
    """Retrieve request statistics for a specific file in an access log."""
    log = open(logFile)
    filename = '/' + filename.lstrip('/')
    access = {}
    for line in log:
        parts = line.split()
        if parts[6] == filename:
            timeStr = parts[3]
            accessTime = time.strptime(timeStr, "[%d/%b/%Y:%H:%M:%S")
            access[parts[0]] = (accessTime, access.get(parts[0], ('', 0))[1] + 1)
    print '%s has been requested by %d people and hit %d times.' % \
          (filename, len(access), sum(map(itemgetter(1), access.itervalues())))
    
    accessTuple = sorted(access.iteritems(), key=itemgetter(1))
    hitWidth = len(str(max([data[1] for user, data in accessTuple])))

    for user, data in accessTuple:
        lastAccess, hits = data
        print 'User: %s Last Access: %s Hits: %s' % \
              ((user+",").ljust(16),
               time.strftime("%a %d-%b-%Y %I:%M:%S %p,", lastAccess),
               str(hits).rjust(hitWidth))

    return accessTuple
Retrieve request statistics for a specific file in an access log.
recipes/Python/438809_Tracking_file_requests_web_server_access/recipe-438809.py