def get_votes(self): # org.add_source("http://app.toronto.ca/tmmis/getAdminReport.do?function=prepareMemberVoteReport") tmpdir = tempfile.mkdtemp() download_files(tmpdir) # read through each csv file files = [f for f in os.listdir(tmpdir)] for f in files: name = f.replace('.csv', '') with open(tmpdir + '/' + f, 'rb') as csvfile: csvfile = csv.reader(csvfile, delimiter=',') next(csvfile) for row in csvfile: session = self.session date = row[1].split()[0] v_type = 'other' passed = 'Carried' in row[6] if not 'tie' in row[6]: yes_count, no_count = row[6].split()[1].split('-') else: yes_count, no_count = 1, 1 motion = row[3].replace('\xc4', '').replace('\xc2', '') vote = Vote(self.jurisdiction.division_name, session, date, motion, v_type, passed, int(yes_count), int(no_count)) vote.vote(name, VOTES[row[5]]) scan_files(tmpdir, f, vote, row) vote.add_source( "http://app.toronto.ca/tmmis/getAdminReport.do") yield vote os.remove(tmpdir + '/' + f) shutil.rmtree(tmpdir)
def get_votes(self): for page in self.iterpages(): for subject in page.xpath('//div[@class="ContainerPanel"]'): dates = subject.xpath(".//font[@color='#276598']/b/text()") motions = [ x.strip() for x in subject.xpath( ".//div[@style='width:260px; float:left;']/text()") ] votes = subject.xpath( ".//div[@style='width:150px; float:right;']") docket = subject.xpath( ".//div[@class='HeaderContent']/b/text()") docket = filter(lambda x: "docket" in x.lower(), docket) docket = docket[0] if docket else None for date, motion, vote in zip(dates, motions, votes): when = dt.datetime.strptime(date, "%m/%d/%Y") motion = motion.strip() if motion == "": self.warning("Skipping vote.") continue v = Vote( session=self.session, organization="Boston City Council", type='other', passed=False, date=when.strftime("%Y-%m-%d"), motion=motion, yes_count=0, no_count=0, ) if docket: v.set_bill(docket) yes, no, other = 0, 0, 0 vit = iter(vote.xpath("./div")) vote = zip(vit, vit, vit) for who, entry, _ in vote: how = entry.text who = who.text if how == 'Y': v.yes(who) yes += 1 elif how == 'N': v.no(who) no += 1 else: v.other(who) other += 1 for count in v.vote_counts: count['count'] = { "yes": yes, "no": no, "other": other }[count['vote_type']] v.add_source(DURL, note='root') yield v