1,234
edits
Changes
→Successful requests menu
Apache Log Analyser - Main Menu
===============================
1) Successful requestsRequests2) Failed requestsRequests
q) Quit
</source>
Make sure the line of equal signs is not hard-coded. You must be able to quickly change the title and not have to update a string with some number of extra or fewer equal signs. You might want to make a function to display this line, and use that function for the other menus as well.
The "Reading log files" message must display only once when your program starts, not every time the menu is displayed. You may find it easier to code this functionality after you're done writing the code for the menu itself.
the <b>q</b> option is self-explanatory.
=== Successful requests menu ===
<source>Apache Log Analyser - Successful Requests Menu
==============================================
1) How many total requests (Code 200)
2) How many requests from Seneca (IPs starting with 142.204)
3) How many requests for isomaster-1.3.13.tar.bz2
q) Return to Main Menu
</source>
Each line in the log file is in the following Apache log format:
<source>LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined</source>
One example line is:
<source>109.86.167.47 - - [29/Aug/2017:10:22:49 -0400] "GET /isomaster/releases/isomaster-1.3.13.tar.bz2 HTTP/1.1" 200 245085 "http://littlesvr.ca/isomaster/download/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"</source>
You should use the Python <b>re</b> module, look [https://docs.python.org/3/library/re.html here] for documentation. You may use the following regular expression to extract the components from each line:
<source>([(\d\.)]+) - - \[(.*?)\] "(.*?)" (\d+) (\d+) "(.*?)" "(.*?)"</source>
The questions are self-explanatory, provide answers formatted as you see fit.