Question
*PYTHON* Write a program that reads in two files: a template and a database and writes junk mails (save your outputs as the .txt format)
*PYTHON*
Write a program that reads in two files: a template and a database and writes junk mails (save your outputs as the .txt format) using the template email format.
The template file contains text and tags. The tags have the form |1| |2| |3| and need to be replaced with the first, second, third, field in the current database record. A typical database looks like this:
Mr.|Harry|Morgan|1105 Torre Ave.|Cupertino|CA|95014
Dr.|John|Lee|702 Ninth Street Apt. 4|San Jose|CA|95109
Miss|Evelyn|Garcia|1101 S. University Place|Ann Arbor|MI|48105
And here is a typical form letter:
To:
|1| |2| |3|
|4|
|5|, |6| |7|
Dear |1| |3|:
You and the |3| family may be the lucky winners of $10,00,000 in the Python
clearinghouse sweepstakes. Please visit our offices in |5|, |6| to
confirm your winning status.
Sincerely,
Scammers
Given that there are three people in the database file, your program should be able to generate three junk mails automatically. For your output files (i.e., three junk mails), ensure to save the name as first name + last name.txt. In other words, once I execute your codes, there will be three files generated automatically with the file names of HarryMorgan.txt, HarryMorgan.txt, and JohnLee.txt in my side.
(Tips: use .replace() to replace the value and use .write() to write into the junk mail template; use .read() to extract a string that contains characters in the file).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started