Question: Please use the program from the file: gen_acc_data.py , and copy and paste it directly, and then run it and verify that a list of
Please use the program from the file: gen_acc_data.py, and copy and paste it directly, and then run it and verify that a list of account data were successfully written to a .txt file:
gen_acc_data.py:
from time import ctime
from random import randint, choice
from string import ascii_lowercase
maxint=1500000000
doms = ( 'com', 'edu', 'net', 'org', 'gov' )
text_file_name = 'lab7_emails.txt'
data_file = open(text_file_name, 'w')
for i in range(randint(5, 10)): # the length of data file is between 5 and 10 lines
dtint = randint(0, maxint) # pick date
dtstr = ctime(dtint) # date string
shorter = randint(4, 7) # login shorter
em = ''
for j in range(shorter): # generate login
em += choice(ascii_lowercase)
longer = randint(shorter, 12) # domain longer
dn = ''
for j in range(longer): # create domain
dn += choice(ascii_lowercase)
data_file.write('%s::%s@%s.%s::%d-%d-%d ' % (dtstr, em, dn, choice(doms), dtint, shorter, longer))
Sample output of the program:
Sat Feb 6 06:21:14 2016::jjkpxad@eegrsxdx.org::1454714474-7-8 Fri Apr 8 17:35:32 2011::wxazig@nsihrihck.gov::1302258932-6-9 Sun Mar 23 16:54:41 1980::jeyk@mjlhtscicgqi.edu::322653281-4-12 Tue Jun 1 22:25:19 1999::nemqg@iubwxm.net::928250719-5-6 Fri Jun 25 20:20:59 1993::xvnhq@fssysua.net::741014459-5-7 Wed May 17 13:24:12 1995::zzwtva@apimrmxc.gov::800691852-6-8 Thu Jun 4 23:21:06 1992::mamto@ggmxxbxqu.edu::707674866-5-9
Task and requirements is to create regular expressions to:
- Extract the complete timestamps from each line.
- Extract the complete e-mail address from each line.
- Extract only the months from the timestamps.
- Extract only the years from the timestamps.
- Extract only the time (HH:MM:SS) from the timestamps.
- Extract only the login and domain names (both the main domain name and the high-level domain together) from the e-mail address.
- Extract only the login and domain names (both the main domain name and the high-level domain) from the e-mail address.
- Replace the e-mail address from each line of data with your e-mail address.
- Extract the months, days, and years from the timestamps and output them in Mon Day, Year format, iterating over each line only once.
The program should be integrated with the given program above such that each time the program is tested/run, it generates a new list of account data.
In Python include docstring and comments
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
