imported mpl_figure_editor from traits tutorial
[BS_AY250.git] / week5 / g.py
blobc7b56c4215590816a66b99601aff32f803a36b16
1 '''
2 AY250 HW5 G
3 Insert another record into the polls table
4 Author: Bryan Steinbach
5 '''
7 import sys
8 import os
9 import sqlite3
11 tablefn = 'poll'
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
17 mons = str(moni)
18 if len(mons) == 1:
19 mons = '0'+mons
21 return '2010-'+mons+'-'+day
23 words = sys.argv[1:]
24 if len(words) < 9:
25 print "usage: python g.py <state> <gop frac> <dem frac> <ind frac> <month1> <day1> <month2> <day2> <pollster>"
26 exit(1)
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)
36 c = conn.cursor()
38 c.execute(''' insert into polls
39 values (?,?,?,?,?,?,?) ''',(state,gop,dem,ind,date1,date2,pollster))
41 conn.commit()
43 c.close()