Пример #1
0
    (name, party, date, session_id, res)
where:
    name is the name of the MP
    party indicates the party affiliation of the MP
    date is the date the vote was submitted, in yyyy-mm-dd format
    session_id is the number of the session in the corresponding day, numbered from 0
    res is one of yes, no, abstain, or absent
"""
stats_by_name = {}
session_ids = set()
parties = []
dates = []
total_counts = {'yes': 0, 'no': 0, 'abstain': 0, 'absent': 0}

for vote in all_votes:
    name = englishfy(vote[0].encode('utf8'))
    party = englishfy(vote[1].encode('utf8'))
    date = vote[2]
    session_id = vote[3]
    res = vote[4]
    if name not in stats_by_name.keys():
        # first time we see this guy
        stats_by_name[name] = {'yes': 0, 'no': 0, 'abstain': 0, 'absent': 0, 'parties': []}
    mp_stats = stats_by_name[name]
    mp_stats[res] += 1
    if party not in mp_stats['parties']:
        mp_stats['parties'].append(party)
    if (date, session_id) not in session_ids:
        session_ids.add((date, session_id))
    if date not in dates:
        dates.append(date)
Пример #2
0
sys.path.append('..')
from connect import *
from util import englishfy

# go over all votes and make a list of the names of all people who ever voted
cur.execute("SELECT * FROM mp_votes")
all_votes = cur.fetchall()
names = []
for vote in all_votes:
    if vote[0] not in names:
        names.append(vote[0])
names.sort()

# write the names, in Bulgarian, to a file
open('mp_names_bg.txt', 'w').close() # this cleans the file
bgnames = open('mp_names_bg.txt', 'w')
for name in names:
    bgnames.write(name.encode('utf8'))
    bgnames.write("\n")
bgnames.close()

# write the names, in (approximately) English, to another file
open('mp_names_en.txt', 'w').close() # this cleans the file
ennames = open('mp_names_en.txt', 'w')
bgnames = open('mp_names_bg.txt', 'r')
names_string = bgnames.read()
ennames.write(englishfy(names_string))
ennames.close()