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
  • Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text...

    Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text file (customer.txt) and put names and phone numbers into it. each name has to have its own phone number right under it. In the QT window, the user has to enter a name and the program prints the phone number related to it. NB: If the user input a name that doesn't exist, the program should print an error message. Text file example: QT...

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • please type code in Python find all the VALID email address in this input text file...

    please type code in Python find all the VALID email address in this input text file and store them as a single column of valid email addresses in an output text file labeled OutputFile First cut/paste the block of text below into a separate text file and label that data file InputFile: FinancialAid Email: finaid@myschool.edu Scholarships Financial Aid Phone: 979-555-3236 Email: random@ubx.net Financial visit@tamu.com Aid helpdesk@tamu.notvalid Help Desk Central fakename@egr.msu.org Dean's Office      Jill Educational Program Coordinator II    Create...

  • In Python Provide me with your code file, output file and the text file Create a...

    In Python Provide me with your code file, output file and the text file Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average. Important: The two files that you are creating will contain different numbers.

  • USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first...

    USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following from: first.last@mycollege.edu

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • Python programming question Using an adjacency matrix: Take a txt file and have the program read...

    Python programming question Using an adjacency matrix: Take a txt file and have the program read it and output the contents into an adjacency matrix. - The txt file would have the size of the matrix and a list of names. - Print the filled matrix of the names - After each iteration, the program will ask, 'continue'? - Show how to swap names for the next iteration(Program would take an input of two names and swap them) Example: input:...

  • a. Provide me with your code file, output file and the text file. 1. Create a...

    a. Provide me with your code file, output file and the text file. 1. Create a file with a series of integers. Save it as numbers. txt. Write a program that reads all the numbers and calculates their sum . 2. Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average. Important: The two files that you are creating will contain different...

  • Python Programming Write a program that counts how often a word occurs in a text file....

    Python Programming Write a program that counts how often a word occurs in a text file. Input: Ask the user for the name of an ASCII text file. Output: Display the numbers of top frequently appeared words and their frequencies. Pseudocode: 1) Read the file 2) Split the file into words 3) Count each word 4) Sort the words by frequencies, starting with the most frequent ones 5) Internally you should use some sort of data structure to keep track...

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