Simulating from the command line

Rather than writing the code to simulate the login attempts every time, we can package this up in a script that we can easily run from the command line. The Python standard library has the argparse module (https://docs.python.org/3/library/argparse.html), which allows us to specify arguments to our script that can be supplied from the command line. Let's take a look at the simulate.py file to see how to do this.

We start with our imports:

import argparseimport datetime as dtimport osimport loggingimport randomimport login_attempt_simulator as sim

In order to provide status updates when using this from the command line, we are going to set up logging messages using the standard library's logging module (https://docs.python.org/3/library/logging.html ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.