Skip to content

Commit 681a26c

Browse files
committed
"Finished Assignment 8"
1 parent 228ebe5 commit 681a26c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Assignment8/family_rodent_mayhem.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def get_family(inputline):
1414
"""Find the rodent family name from text file"""
15-
family_re = "(Family ?(..[A-Z][a-z]+..))"
15+
family_re = "Family.\[\[([A-Z][a-z]+)"
1616
for family in family_re:
1717
family_search = re.search(family_re, inputline)
1818
if family_search:
@@ -21,23 +21,26 @@ def get_family(inputline):
2121

2222
def get_species(inputline):
2323
"""Find the rodent genus and species name from text file"""
24-
species_re = "([A-Z][a-z]+ [a-z]+)" #parens makes a group for matching items
24+
species_re = "\*\*\*\*\*....([A-Z][a-z]+ [a-z]+)"
2525
species_search = re.search(species_re, inputline)
2626
if species_search:
2727
return species_search.group(1)
28-
28+
2929
con = dbapi.connect("rodent_names")
30-
cur = con.cursor()
30+
cur = con.cursor()
31+
cur.execute("DROP TABLE if exists Rodents")
32+
cur.execute("CREATE TABLE Rodents (Family VARCHAR, Species VARCHAR)")
33+
34+
3135

3236
for line in inputfile:
3337
family = get_family(line)
34-
species = get_species(line)
3538
if family:
36-
results.append(family)
37-
cur.execute("INSERT INTO Rodents VALUES (?)", (family,))
39+
current_family = family
40+
species = get_species(line)
3841
if species:
3942
results.append(species)
40-
cur.execute("INSERT INTO Rodents VALUES (?)", (species,))
43+
cur.execute("INSERT INTO Rodents VALUES (?,?)", (current_family, species,))
4144
else:
4245
nomatch.append(line)
4346
con.commit()

0 commit comments

Comments
 (0)