#!/usr/bin/env python3 # vim: wrapmargin=0 textwidth=0 smarttab expandtab tabstop=2 shiftwidth=2 """Process Apache access.log lines to find highest rate of /upload/.""" import argparse from collections import deque import datetime import dateutil.parser import fileinput import re def process_log_file( input_file: str ='-', request_text: str = '/upload/', window_size: int = 1, ) -> None: """ Process the indicated log file to determine peak rate of interesting lines. :param input_file: Name of input file, `-` for stdin :param request_text: The text that denotes an interesting line :param window_size: Time, in seconds, for the window to assess """ print(f'With:\n\tinput_file: "{input_file}"\n\trequest_text: "{request_text}"') with fileinput.FileInput(files=(input_file)) as f: apache_re = re.compile(r'^(?P[.:0-9a-fA-F]{3,39}) - - \[(?P[^\]]+)\] (?P.*' + request_text + '.*)$') print(f'Apache RE:\n{apache_re}\n') apache_datetime_re = re.compile( r'^(?P[0-9]{2})/(?P[^/]{3})/(?P[0-9]{4}):(?P