A simple Python application to find the most active cookies from a log file for a specific day in UTC timezone.
- Parses cookie log files.
- Counts occurrences of each cookie for a specified date.
- Returns the most frequent cookie(s) for that date.
- Python 3.7 or higher
- Any additional dependencies (if any, e.g.,
zoneinfo
for timezone functionality)
your_project/
│
├── logcounter.py # Main application code
├── cookie_log.csv # Sample cookie log file
└── test_logcounter.py # Test code for the application
└── README.md # Project documentation
Before you begin, ensure you have Python installed on your machine. You can check if Python is installed by running:
python --version
If Python is not installed, download and install it from python.org.
-
Download the project source code or get them from the repository:
git clone <repository-url>
-
Change into the project directory:
cd <project-directory>
-
(Optional) Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
To run the cookie counter application, use the following command:
python logcounter.py -f <path_to_cookie_log_file> -d <YYYY-MM-DD>
python logcounter.py -f cookie_log.csv -d 2018-12-09
This command will output the most active cookie(s) for the specified date (e.g., December 9, 2018).
To ensure the application is functioning as expected, you can run the test suite provided:
python3 -m unittest test_logcounter.py
To run a specific test case, use:
python -m unittest test_logcounter.TestValidator.test_validate_date_invalid_format
The input CSV log file should be structured as follows:
cookie,timestamp
cookie_name_1,2023-10-01T12:34:56+00:00
cookie_name_2,2023-10-01T09:21:00+00:00
...
- The first line is a header.
- Subsequent lines contain cookies and their respective timestamps.