3 Build sqlite3 table of names and pictures
4 Author: Bryan Steinbach
18 conn
= sqlite3
.connect(tablefn
)
20 def retrieve_state(state
):
22 c
.execute('''select polls.gop,polls.dem,polls.ind,polls.date1
23 from polls,names where polls.state = ? and names.state = ? order by polls.date1 asc''',(state
,state
))
25 gopfracs
,demfracs
,indfracs
,dates
= [],[],[],[]
27 gopfrac
,demfrac
,indfrac
,date
= r
28 gopfracs
.append(gopfrac
)
29 demfracs
.append(demfrac
)
30 indfracs
.append(indfrac
)
36 c
.execute('''select gop,dem,ind from names where state = ? ''',(state
,))
38 gopname
,demname
,indname
= c
.next()
41 dates
= np
.array(dates
)
42 dates
= pl
.datestr2num(dates
)
43 dates
= (1 + dates
/365.242199 - 2010)*365.242199
47 pl
.plot(dates
,gopfracs
,color
='red',label
=gopname
)
49 pl
.plot(dates
,demfracs
,color
='blue',label
=demname
)
51 pl
.plot(dates
,indfracs
,color
='blue',label
=indname
)
55 pl
.xlabel('Date (Day of 2010)')
56 pl
.ylabel('Percent polling for candidate')
58 pl
.title('Polling data for '+state
)
67 print "usage: python f.py <2 char state abbreviation>"