'''
This program is to read through any number of inputs (that is only: .txt files) the user passes through the sys.argv (through the terminal only). The file should only be a .txt file. Which means there is a conditional. Then the program should print those results to the terminal.
'''
import sys
def find_email(line1):
'''
We must find the 'email address pattern' that is: username@domainname.domain
There is only one symbol to help the read file method catch and print those email addresses:
The @ symbol and then the two ' ' spaces at each end of the email address.
when we call from main() we must read the log file containing emails.
'''
line1 = [' ', '@', ' ']
at_postion = line1.find('@')
first_place = line1.find(' ', at_postion)
second_place = line1.find(' ', at_postion)
return line1[second_place: first_place + 1]
def main():
'''
Main for sys argv input and one wrong file conditional.
'''
result = []
results = []
sys.argv(input('Enter .txt file: '))
with open('r', sys.argv) as input:
for result in find_email():
result.append(results)
print(result)
if sys.argv(input('Enter .txt file: ')) == type(str):
find_email()
else:
print("Error, enter .txt files only")
exit()
print(results)
if __name__ == "__main__":
main()
Note again: I am only supposed to use string methods to find these spam email addresses in the log file using read file method and print those emails to the terminal. I am also certain that I have not encountered other conditional errors yet, so it is a work in progress. Also not that this is a school assignment.
a) With the correct sys.argv values. Given that a user can enter as much input as they want. Show error messages or usage in case of an error input.
b) Find all email addresses from a given logfile, considering I can enter a different file. DO NOT use any static file.
c) Using the code modularity, refactor your code.
I ran the code a few times and rewritten and I am still getting a variety of errors, I am certain that I am not conceptualizing some critical things. Please point out what you think I am missing or not understanding.
Please feel free to point me to some resources that can help me understand the following: 1) code modularity, 2) read file method, 3) anything I got right, and 4) anything I forgot.