def IterVote(text, sitting_dict):
    text = re.sub(u'(議員)(計\s?\d+\s?位)', u'\g<1>:\g<2>', text)
    print sitting_dict["uid"]
    vote_count = 1
    pre_match_end = 0
    for match in Namelist_Token.finditer(text):
        vote_seq = str(vote_count).zfill(3)
        vote_dict = {
            'uid': '%s-%s' % (sitting_dict["uid"], vote_seq),
            'sitting_id': sitting_dict["uid"],
            'vote_seq': vote_seq,
            'date': sitting_dict["date"],
            'content': GetVoteContent(text[pre_match_end:match.end()])
        }
        print '=' * 20
        print vote_seq
        UpsertVote(vote_dict)
        ref = {'agree': 1, 'disagree': -1, 'abstain': 0}
        for key, value in ref.items():
            if match.group(key):
                names = re.sub(u'[、:,:,]', ' ',
                               re.sub(u'\s', '', match.group(key)))
                for councilor_id in common.getCouncilorIdList(c, names):
                    id = common.getDetailIdFromUid(
                        c, councilor_id, sitting_dict['election_year'],
                        sitting_dict['county'])
                    if id:
                        VoteVoterRelation(id, vote_dict['uid'], value)
        vote_count += 1
        pre_match_end = match.end()
Beispiel #2
0
 candidate['election_year'] = election_year
 if candidate['type'] == 'mayors':
     candidate['constituency'] = 0
     candidate[
         'candidate_uid'], created = common.get_or_create_moyor_candidate_uid(
             c, candidate)
 else:
     candidate[
         'candidate_uid'], created = common.get_or_create_candidate_uid(
             c, candidate)
 candidate['candidate_term_uid'] = '%s-%s' % (
     candidate['candidate_uid'], election_year)
 candidate[
     'councilor_uid'], created = common.get_or_create_councilor_uid(
         c, candidate, create=False)
 candidate['councilor_term_id'] = common.getDetailIdFromUid(
     c, candidate['councilor_uid'], election_year, candidate['county'])
 candidate['councilor_terms'] = common.councilor_terms(
     c, candidate) if created else None
 if candidate['type'] == 'mayors':
     candidate['mayor_uid'] = candidate['candidate_uid']
     if candidate['mayor_uid']:
         candidate['mayor_terms'] = common.mayor_terms(c, candidate)
     candidate['legislator_uid'] = common.get_legislator_uid(
         c_another, candidate['name'])
     candidate['legislator_data'] = common.get_legislator_data(
         c_another, candidate['legislator_uid'])
     if candidate['legislator_uid']:
         candidate['legislator_terms'] = common.legislator_terms(
             c_another, candidate)
         candidate[
             'legislator_candidate_info'] = common.get_legislator_candidate_info(
                                           ('petitioned_by', -1, True)]:
            for i, name in enumerate(bill.get(key, [])):
                name = common.normalize_person_name(name)
                name = re.sub(u'副?議長', '', name)
                if name:
                    # councilor in bill might not on this election_year
                    id, created = common.get_or_create_councilor_uid(
                        c,
                        dict(
                            zip([
                                'name', 'county', 'election_year',
                                'constituency'
                            ], [name, county, bill['election_year'], None])),
                        create=False)
                    if id:
                        detail_id = common.getDetailIdFromUid(
                            c, id, bill['election_year'], county)
                        CouncilorsBills(detail_id, bill['uid'],
                                        i == priproposer, petition)
        update_sponsor_param(bill['uid'])
        bill_party_diversity(bill['uid'])
    # Update bills_party_diversity of People
    for councilor_id in councilors(f_election_year, county):
        personal_vector(councilor_id)
conn.commit()
print 'bills done'

c.execute('''
    SELECT
        councilor_id,
        COUNT(*) total,
        SUM(CASE WHEN priproposer = true AND petition = false THEN 1 ELSE 0 END) priproposer,