12
12
13
13
def get_family (inputline ):
14
14
"""Find the rodent family name from text file"""
15
- family_re = "( Family ?(..[ A-Z][a-z]+..) )"
15
+ family_re = "Family.\[\[([ A-Z][a-z]+)"
16
16
for family in family_re :
17
17
family_search = re .search (family_re , inputline )
18
18
if family_search :
@@ -21,23 +21,26 @@ def get_family(inputline):
21
21
22
22
def get_species (inputline ):
23
23
"""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]+)"
25
25
species_search = re .search (species_re , inputline )
26
26
if species_search :
27
27
return species_search .group (1 )
28
-
28
+
29
29
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
+
31
35
32
36
for line in inputfile :
33
37
family = get_family (line )
34
- species = get_species (line )
35
38
if family :
36
- results . append ( family )
37
- cur . execute ( "INSERT INTO Rodents VALUES (?)" , ( family ,) )
39
+ current_family = family
40
+ species = get_species ( line )
38
41
if species :
39
42
results .append (species )
40
- cur .execute ("INSERT INTO Rodents VALUES (?)" , (species ,))
43
+ cur .execute ("INSERT INTO Rodents VALUES (?,? )" , (current_family , species ,))
41
44
else :
42
45
nomatch .append (line )
43
46
con .commit ()
0 commit comments