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 if os
.path
.exists(tablefn
):
23 conn
= sqlite3
.connect('poll')
27 c
.execute(''' create table pics
28 (name text, url text) ''')
30 with
open(rawfn
) as f
:
31 f
.readline() # Skip first line
32 for line
in f
.readlines():
33 words
= line
.split(',')
34 state
,dem
,gop
,ind
,incpar
= words
35 names
= [x
.strip() for x
in (dem
,gop
,ind
) if x
.strip() != '']
38 c
.execute(''' insert into pics
39 values (?,?) ''',(name
,base_url
+name
+ext
))
44 c
.execute('select * from pics order by name')