Exemple #1
0
def get_voters_ternopil_all_files(files_path):
    """
    takes folder with txt files to process. Subfolders allowed
    """
    voters = {}
    files_lst = get_txt_files_list(files_path)

    votings_count = 0

    for fname in files_lst:
        current_voters = get_voters_ternopil(fname)
        if current_voters:
            votings_count += 1
        update_voters(voters, current_voters)

    # print('total files:', votings_count)
    with open('ternopil_misto.xls', 'w') as output_file:
        output_file.write('\t'.join([
            'ПІБ', 'Так', 'Ні', 'Утрималися', 'Не голосували', 'Відсутні', '\n'
        ]))
        for voter, summary in voters.items():
            file_ln = '\t'.join([
                voter,
                str(summary['ЗА']),
                str(summary['ПРОТИ']),
                str(summary['УТРИМАВСЯ']),
                str(summary['НЕ ГОЛОСУВАВ']),
                str(summary['відсутній']),
                '\n',
            ])
            output_file.write(file_ln)
Exemple #2
0
def get_all_voters(folderpath):
    path_pattern = '/'.join([folderpath, '**/*.txt'])
    filepaths = glob.glob(path_pattern, recursive=True)
    voters = {}
    for filepath in filepaths:
        current_voters = get_voters(filepath)
        update_voters(voters, current_voters)
    votings = ['ЗА', 'ПРОТИ', 'УТРИМАВСЯ', 'Не голосував']
    update_voters_with_zeros(voters, votings)
    return voters
Exemple #3
0
def get_voters_khmel_all_files(files_path):
    """
    takes folder with txt files to process. Subfolders allowed
    """

    voters = {}
    files_lst = get_txt_files_list(files_path)

    votings_count = 0

    for fname in files_lst:
        current_voters = get_voters_khmel(fname)
        if current_voters:
            votings_count += 1
        else:
            print("Empty:", fname)
        update_voters(voters, current_voters)

    print("Votings count:", votings_count)

    fill_registry(voters, files_path)
    for voter in sorted(voters):
        print('\t'.join([voter, str(voters[voter]['registered'])]))

    # print('total files:', votings_count)
    vote_types = ['ЗА', 'УТРИМАЛОСЬ', 'ПРОТИ', 'НЕ ГОЛОСУВАЛО']
    with open('khmel_obl.xls', 'w') as output_file:
        output_file.write('\t'.join([
            'ПІБ', 'Партія', 'Так', 'Ні', 'Утрималися', 'Не голосували',
            'Зареєструвалося', '\n'
        ]))
        for voter, summary in voters.items():

            party = [vote for vote in summary if vote not in vote_types]
            if len(party) == 0:
                party = ''
            elif len(party) == 1:
                party = party[0]
            else:
                print("Multiple parties:", party)
                party = ', '.join(party)

            file_ln = '\t'.join([
                voter,
                party,
                str(summary['ЗА']),
                str(summary['ПРОТИ']),
                str(summary['УТРИМАЛОСЬ']),
                str(summary['НЕ ГОЛОСУВАЛО']),
                '\n',
            ])
            output_file.write(file_ln)
Exemple #4
0
def get_voters_lviv_all_files(files_path):
    """
    takes folder with txt files to process. Subfolders allowed
    """
    voters = {}
    files_lst = get_txt_files_list(files_path)

    votings_count = 0

    for fname in files_lst:
        current_voters = get_voters_lviv(fname)
        if current_voters:
            votings_count += 1
        update_voters(voters, current_voters)

    print(voters)

    # print('total files:', votings_count)
    vote_types = ['ЗА', 'УТРИМАВСЯ', 'ПРОТИ', 'НЕ ГОЛОСУВАВ', 'відсутній']
    with open('lviv_misto.xls', 'w') as output_file:
        output_file.write('\t'.join([
            'ПІБ', 'Партія', 'Так', 'Ні', 'Утрималися', 'Не голосували',
            'Відсутні', '\n'
        ]))
        for voter, summary in voters.items():
            party = [vote for vote in summary if vote not in vote_types]
            if len(party) == 0:
                party = ''
            elif len(party) == 1:
                party = party[0]
            else:
                print("Multiple parties:", party)
                party = ', '.join(party)

            file_ln = '\t'.join([
                voter,
                party,
                str(summary['ЗА']),
                str(summary['ПРОТИ']),
                str(summary['УТРИМАВСЯ']),
                str(summary['НЕ ГОЛОСУВАВ']),
                str(summary['відсутній']),
                '\n',
            ])
            output_file.write(file_ln)