Question

Your mission in this programming assignment is to create a Python program that will take an...

Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt file, from the user.   ‐ Prompt for and get the desired output filename, a .txt file, from the user. ‐ Process the contents of the input file through email and phone number regular expressions. ‐ Write the pattern match results to the output file.   ‐ Create a ZIP archive of the output file.   ‐ Challenge. Can you get your phone regex to correctly process numbers in the (xxx)xxx‐xxxx format? Notes ‐ Hint. Use the textbook “Project: Phone Number and Email Address Extractor” on pp 165 – 169 as the core of your program. You know this code well from Programming Assignment 4. ‐ Hint. Be mindful of closing your various objects at the appropriate time.   ‐ I will supply my own input file. In other words, I’m going to evaluate your program using my file.   ‐ I will park your .py file in the same folder that my input file (.txt) is. Your program is to create the output file (.txt) and ZIP the files in the current working directory, which will be the same folder as the .py and .txt files are. No need to designate absolute or relative paths.    ‐ Remember the P‐word? Pseudocode could be your friend in this assignment. I recommend you develop your algorithm via pseudocode before you put fingers to keyboard. ‐ Divide and Conquer. In your pseudocode, determine the major parts of the program. As you start to write source code, work on one piece at a time. Get that piece working and then move to the next piece.

Hint instructions on 165 - 169 below:

rint('Task I\nRegular Expression (Regex)')
print()

#! python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.

import pyperclip, re

# Create phone number Regrex
phoneRegex = re.compile(r'''(
    (\d{3}|\(\d{3}\))?                    # area code
    (\s|-|\.)?                            # separator
    (\d{3})                               # first 3 digits
    (\s|-|\.)                             # Separator
    (\d{4})                               # last 4 digits
    (\s*(ext|x|ext.)\s*(\d{2,5}))?        # extension
    )''', re.VERBOSE)

# TODO: Create email regex

# TODO: Find matches in clipboard text.

# TODO: Copy results to the clipboard.


# phoneAndEmail.py - Finds phone numbers and email address on the clipboard.

# Create email regex
emailRegex = re.compile(r'''(
    [a-zA-Z0-9._%+-]+                    # username
    @                                    # @ symbol
    [a-zA-Z0-9.-]+                       # domain name
    (\.[a-zA-Z]{2,4})                    # dot-something
    )''', re.VERBOSE)

# TODO: Find matches in clipboard text.

# TODO: Copy results to the clipboard


# phoneAndEmail.py - Find phone numbers and email.

# Find matches in clipboard text.
text = str(pyperclip.paste())
matches = []
for groups in phoneRegex.findall(text): # use for loop to fina phone regex
    phoneNum = '-'.join([groups[1], groups[3], groups[5]]) # join phone numbers
    if groups[8] != ' ':
        phoneNum += ' x' + groups[8]
    matches.append(phoneNum) # add phone number
for groups in emailRegex.findall(text): # use for loop to find all email Regex
    matches.append(groups[0]) # add and match list

# TODO: Copy results to the clipboard

# phoneAndEmail.py - Finds phone numbers and email address on the clipboard.

for groups in emailRegex.findall(text):
    matches.append(groups[0])

# Copy results to clipboard.
if len(matches) > 0:
    pyperclip.copy('\n'.join(matches)) # use pyperclip to copy the join clipboard
    print('Copied to clipboard:') # print clipboard copied to the screen
    print('\n'.join(matches)) # print join matches list to the screen
else:
    print('No phone numbers or email addresses found.') # print no phone or email to screen if not found
print()

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Your mission in this programming assignment is to create a Python program that will take an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT