コード例 #1
0
ファイル: scrutins.py プロジェクト: goulu/smartvoteFR
        ref = groupe.find('organeRef').text
        pm = groupe.find('vote/positionMajoritaire').text
        votes = ['contre', 'abstention', 'pour']
        default = votes.index(pm) - 1  # against=-1, no vote=0

        # first we consider all members of the group voted as default:
        for actor in organes[ref]:
            line[acteurs[actor]] = default

        # then remove those who didn't vote:
        for votant in groupe.find('vote/decompteNominatif/nonVotants'):
            ref = votant.find('acteurRef').text
            try:
                del line[acteurs[ref]]
            except KeyError:
                pass  # already deleted (in a different group)

        # and modify those who voted differently:
        for i, vote in enumerate(votes):
            for votant in groupe.find('vote/decompteNominatif/%ss' % vote):
                ref = votant.find('acteurRef').text
                try:
                    line[acteurs[ref]] = i - 1
                    print(acteurs[ref], 'voted', vote)
                except KeyError:
                    logging.error("actor ref %s doesn't exist" % ref)

    res.append(line)

res.save('votes.csv', encoding='iso-8859-15')