forked from sarthakd999/Hacktoberfest2021-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailfetcher.py
33 lines (32 loc) · 910 Bytes
/
emailfetcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import re
fileToRead = 'readText.txt'
fileToWrite = 'emailExtracted.txt'
delimiterInFile = [',', ';']
def validateEmail(strEmail):
# .* Zero or more characters of any type.
if re.match("(.*)@(.*).(.*)", strEmail):
return True
return False
def writeFile(listData):
file = open(fileToWrite, 'w+')
strData = ""
for item in listData:
strData = strData+item+'\n'
file.write(strData)
listEmail = []
file = open(fileToRead, 'r')
listLine = file.readlines()
for itemLine in listLine:
item =str(itemLine)
for delimeter in delimiterInFile:
item = item.replace(str(delimeter),' ')
wordList = item.split()
for word in wordList:
if(validateEmail(word)):
listEmail.append(word)
if listEmail:
uniqEmail = set(listEmail)
print(len(uniqEmail),"emails collected!")
writeFile(uniqEmail)
else:
print("No email found.")