-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsweeper.py
76 lines (70 loc) · 2.34 KB
/
sweeper.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def sweep(inputFileName):
f = open(inputFileName, "r")
outFile = open("badEntries.txt", "w")
charCount = 1
invalidEntry = False #Tracks if the entry is invalid
letter = False #Tracks if a letter has been found
at = False #Tracks if an '@' has been found
period = False #Tracks if a '.' has been found
dash = False #Tracks if a '-' has been found
lastCharAt = False #Previous char was an '@'
lastCharPeriod = False #Previous char was a '.'
entry = ""
currentChar = "Unset"
writtenTo = False
while(True):
currentChar = f.read(1)
if(currentChar == ""): #Reached end of file
break
cVal = ord(currentChar)
if(currentChar == ','): #Marks the end of the current entry
if(lastCharPeriod == True or lastCharAt == True or (at == False and dash == False) or (period == False and dash == False)):
invalidEntry = True
elif((dash == True and charCount != 13) or charCount < 6):
invalidEntry = True
if(invalidEntry == True):
if(writtenTo == True):
outFile.write(", ")
outFile.write(entry)
writtenTo = True
entry = "" #Setting up for next entry
charCount = 1
invalidEntry = False
letter = False
at = False
period = False
dash = False
continue #Begins a new entry
elif(invalidEntry == True):
True #Do nothing, just cotinue the loop
elif(currentChar == '@'):
if(letter == False or at == True or period == True or dash == True):
invalidEntry = True
at = True
elif(currentChar == ' ' or currentChar == '\n'):
continue
elif(currentChar == '-'):
if(letter == True or at == True or period == True or (charCount != 4 and charCount != 8)):
invalidEntry = True
dash = True
elif(currentChar == '.'):
if(dash == True or period == True or at == False):
invalidEntry = True
period = True
elif((cVal >= ord('A') and cVal <= ord('Z')) or (cVal >= ord('a') and cVal <= ord('z'))):
if(dash == True):
invalidEntry = False
letter = True
elif(cVal >= ord('0') and cVal <= ord('9')):
if(dash == True and letter == True): #Not necessary, but extra precaution
invalidEntry = True
entry += currentChar #Adding currentChar to the current entry
charCount += 1
if(entry != "" and invalidEntry == True): #Writing last invalid entry
if(writtenTo == True):
outFile.write(", ")
outFile.write(entry)
f.close()
outFile.close()
return
sweep("phoneNumbersInvalid.txt")