3 Build sqlite3 table of states and names
4 Author: Bryan Steinbach
10 rawfn
= 'candidate_names.txt'
13 if not os
.path
.exists(rawfn
):
14 print "Error, missing file %s"%rawfn
17 conn
= sqlite3
.connect('poll')
21 c
.execute(''' create table names
22 (state text, gop text, dem text, ind text, incpar text)''')
24 with
open(rawfn
) as f
:
25 f
.readline() # Skip first line
26 for line
in f
.readlines():
27 words
= line
.strip().split(',')
28 state
,dem
,gop
,ind
,incpar
= words
29 dem
,gop
,ind
,incpar
= [x
.strip() for x
in (dem
,gop
,ind
,incpar
)]
30 c
.execute(''' insert into names
31 values (?,?,?,?,?) ''',(state
,gop
,dem
,ind
,incpar
))
36 c
.execute('select * from names order by gop')