Skip to content

Commit fa24ce9

Browse files
Jack AdamJack Adam
authored andcommitted
rewrote without while loops
1 parent fe89e25 commit fa24ce9

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
def main():
44
c = parser.parse_css()
55
h = parser.parse_html()
6-
76
flag = False
87

98
print(f'Identified {c[0][1]} unique classes and {c[1][1]} unique IDs.\n')

parser.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,40 @@
44

55
def parse_css():
66
filepath = helper.intro('css')
7-
classes = {}
8-
ids = {}
7+
classes, ids, found, flag = {}, {}, '', False
98

109
for file in glob(filepath):
1110
with open(file) as f:
1211
print('Read ' + file)
13-
while True:
14-
c = f.read(1)
15-
if (c == '.') or (c == '#'):
16-
cc, found = '', '' + c
17-
while (cc != '{') and (cc != ','):
18-
cc = f.read(1)
19-
if (cc == ';') or (cc == ':'):
20-
found = ''
21-
break
22-
elif (cc != '{') and (cc != ','):
23-
found += cc
24-
if (len(found) > 0):
25-
found = found.strip()
26-
if (found[0] == '.'):
27-
classes[found[1:]] = file
28-
elif (found[0] == '#'):
29-
ids[found[1:]] = file
30-
if not c:
31-
break
3212

33-
if not classes or not ids:
13+
for line in f:
14+
for c in line:
15+
if (c == '.') or (c == '#'):
16+
flag = True
17+
if (c == ';') or (c == ':'):
18+
flag = False
19+
found = ''
20+
if (c == '{') or (c == ','):
21+
if (len(found) > 0):
22+
found = found.strip()
23+
if (found[0] == '.'):
24+
classes[found[1:]] = file
25+
elif (found[0] == '#'):
26+
ids[found[1:]] = file
27+
flag = False
28+
found = ''
29+
if flag == True:
30+
found += c
31+
32+
if not classes and not ids:
3433
print('No .css files in this directory!')
3534
exit(5)
3635
else:
3736
return (helper.remove_dups(classes), helper.remove_dups(ids))
3837

3938
def parse_html():
4039
filepath = helper.intro('html')
41-
cl = set([])
42-
id = set([])
40+
cl, id = set([]), set([])
4341

4442
for filename in glob(filepath):
4543
with open(filename) as f:
@@ -53,7 +51,6 @@ def parse_html():
5351
start = 4
5452
elif piece[:5] == 'class':
5553
start = 7
56-
5754
if start != None:
5855
for char in piece[start:]:
5956
if (char != "'") and (char != '"'):
@@ -64,7 +61,7 @@ def parse_html():
6461
elif start == 7:
6562
cl.add(found)
6663

67-
if not cl or not id:
64+
if not cl and not id:
6865
print('No .html files in this directory!')
6966
exit(6)
7067
else:

0 commit comments

Comments
 (0)