1. Download the text file cc_numbers_python.txt and ensure it is in the same folder you will be using for this assignment.
374957991156897
2720649587451369
412
4658497501236584046584975012365840
44010400919987200
2223405693062581
2220986578452136
P(346953216584752)Q###
2723895874513658
345911586431914
5513658978452165
45678546895123
2222222222222222
DX4#$2226458745632157****p
4654511991978
$()349856987412345349856987412345p!3&
5605630148793205
349876451326598
2720603410587520
5965845362987541
garb@gE376598457845216gaRB@ge
3497584125100365
5598658475132546
2720659845124569
4678956214875
356812345710236
2. Open the text file in Atom to familiarize yourself with its contents. Each line in the file is a possible credit card number that may or may not follow the pattern of one of the major credit card networks.
3. Create a python script named LastnameFirstname03.py.
4. When running this script, the user is expected to supply the name of a file to read in as a program program argument.
5. To ensure the user supplied a file name, implement a program argument check. If there is not exactly 2 program arguments, terminate the script with an appropriate error and usage message.
6. Attempt to open a file object for reading using the file name from the program argument. Terminate the script with an appropriate error message if the file cannot be opened, or if the user does not have read permission on the file.
7. Read through each possible credit card number in the file. Each number is on its own line, therefore read the file line by line.
8. Below are the characteristics for each network's credit card number pattern. Note that this is not an exhaustive list of each pattern, but these are the ones you will be implementing in the script.
9. For each description, create a Regex object. Some descriptions can be combined into a single regex or expressed separately. For example, American Express descriptions can be expressed in one regex pattern or two, it will be up to you how you want to express the pattern. You should have around 6 patterns total. For all regex patterns, do not allow garbage at the beginning or ending of the number. In other words, only the pattern should match.
10. As the script is reading line by line, apply each pattern to determine what kind of credit card number it is. You can use a series of if-statements or elsif. When a number matches a pattern, print the name of the network in all uppercase, followed a colon :, a space, then the number. Only print numbers that match. Numbers that do not match will not have any output.
11. Close all file objects when done.
12. Ensure that your code is sufficiently styled and documented.
In addition to printing the numbers, also write them out to a text file named matched_cc_numbers.txt on separate lines. Have the script overwrite matched_cc_numbers.txt each time the script is run, i.e. do not append.
> python MeyerEdward03.py
Error: Expecting 2 program arguments. Found 1 instead.
usage: python MeyerEdward03.py filename
> python MeyerEdward03.py pew
Error: Cannot find file: pew
> python MeyerEdward03.py 1 2 3 4
Error: Expecting 2 program arguments. Found 5 instead.
usage: python MeyerEdward03.py filename
What the error message looks like if the user does not have read permission on the file.
> python MeyerEdward03.py cc_numbers_python.txt
Error: No read permission: cc_numbers_python.txt
> python MeyerEdward03.py cc_numbers_python.txt
AMEX: 374957991156897
MASTERCARD: 2720649587451369
VISA: 44010400919987200
MASTERCARD: 2223405693062581
AMEX: 345911586431914
MASTERCARD: 5513658978452165
MASTERCARD: 2222222222222222
VISA: 4654511991978
MASTERCARD: 5605630148793205
AMEX: 349876451326598
MASTERCARD: 2720603410587520
MASTERCARD: 2720659845124569
VISA: 4678956214875
Program done.
Rename cc_numbers_python.txt to just rm, without a file extension, and run the script.
> python MeyerEdward03.py rm
AMEX: 374957991156897
MASTERCARD: 2720649587451369
VISA: 44010400919987200
MASTERCARD: 2223405693062581
AMEX: 345911586431914
MASTERCARD: 5513658978452165
MASTERCARD: 2222222222222222
VISA: 4654511991978
MASTERCARD: 5605630148793205
AMEX: 349876451326598
MASTERCARD: 2720603410587520
MASTERCARD: 2720659845124569
VISA: 4678956214875
Program done.