3 Insert another record into the polls table
4 Author: Bryan Steinbach
13 months
= ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
15 def format_date(month
,day
):
16 moni
= months
.index(month
)+1
21 return '2010-'+mons
+'-'+day
25 print "usage: python g.py <state> <gop frac> <dem frac> <ind frac> <month1> <day1> <month2> <day2> <pollster>"
28 state
,gop
,dem
,ind
,mon1
,day1
,mon2
,day2
= words
[:8]
29 pollster
= ' '.join(words
[8:])
31 date1
= format_date(mon1
,day1
)
32 date2
= format_date(mon2
,day2
)
34 conn
= sqlite3
.connect(tablefn
)
38 c
.execute(''' insert into polls
39 values (?,?,?,?,?,?,?) ''',(state
,gop
,dem
,ind
,date1
,date2
,pollster
))