Exemplo n.º 1
0
def returnvotes(votearray,datadir):
#Here we spit out all of the votes sequentially.
	filelist = os.listdir(datadir)
	filelist.sort()
	#print filelist[1]
	numfiles = len(filelist)

	for name in filelist:
		tmp = parliamentdatastructs.votedata()
		votefile = open(datadir+name,"r")
		tmp2 = re.split('_',name)
		tmp.ses = tmp2[1]
		tmp.parl = tmp2[0]
		tmp.vote = str(int(votefile.readline().rstrip()))
		tmp.bill = votefile.readline().rstrip()
		tmp.title = votefile.readline().rstrip()
		tmp.decision = votefile.readline().rstrip()
		while True:
			line = votefile.readline().rstrip()
			if not line:
				line = votefile.readline()
				if not line:
					break
				elif len(line) > 70:
					tmp.description += line[0:70]
					for i in range(70, len(line), 70):
						tmp.description += '-\n' + line[i:i+70] 
				else:
					tmp.description += line	
			else:
				tmp.description += line 
		votefile.close()
		votearray.append(tmp)		
Exemplo n.º 2
0
def recentvotes(currentsitting,datadir,cursitting):
	XML = 'http://www2.parl.gc.ca/HouseChamberBusiness/Chambervotedetail.aspx?Language=E&Mode=1&Parl=%(parliamentnum)s&Ses=%(sessnum)s&FltrParl=%(parliamentnum)s&FltrSes=%(sessnum)s&vote=%(votenum)s&xml=True'

	votedata = parliamentdatastructs.votedata()

	y = currentsitting.last + 1

	while(True):
		xmlurl = XML % {'parliamentnum' : currentsitting.parl, 'sessnum' : currentsitting.ses, 'votenum' : y}
		try:
			myxml = urllib2.urlopen(xmlurl)
			tree = etree.parse(myxml)
		except Exception, e:
			try:
				y += 1
				xmlurl = XML % {'parliamentnum' : currentsitting.parl, 'sessnum' : currentsitting.ses, 'votenum' : y}
				myxml = urllib2.urlopen(xmlurl)
				tree = etree.parse(myxml)
			except Exception, e:
				#print "No vote exists at %s" % xmlurl
				#print e
				y -= 1
				break