3 Build sqlite3 table of names and pictures
4 Author: Bryan Steinbach
10 rawfn
= 'candidate_names.txt'
13 base_url
= 'http://astro.berkeley.edu/~amorgan/candidates/'
16 if not os
.path
.exists(rawfn
):
17 print "Error, missing file %s"%rawfn
20 conn
= sqlite3
.connect('poll')
24 c
.execute(''' create table pics
25 (name text, url text) ''')
27 with
open(rawfn
) as f
:
28 f
.readline() # Skip first line
29 for line
in f
.readlines():
30 words
= line
.strip().split(',')
31 state
,dem
,gop
,ind
,incpar
= words
32 names
= [x
.strip() for x
in (dem
,gop
,ind
) if x
.strip() != '']
35 c
.execute(''' insert into pics
36 values (?,?) ''',(name
,base_url
+name
+ext
))
41 c
.execute('select * from pics order by name')