<commit_before># Copyright 2015 <NAME> <<EMAIL>>
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.

import argparse
from collections import OrderedDict
import csv
from enum import Enum
import json
import sys

from vk.api import API, Language
from vk.user import UserField

_OUTPUT_USER_FIELDS = UserField.UID, UserField.FIRST_NAME, UserField.LAST_NAME

def _query_friend_list(api, user):
    return api.friends_get(user.get_uid(), fields=_OUTPUT_USER_FIELDS)

def _filter_user_fields(user):
    new_user = OrderedDict()
    for field in _OUTPUT_USER_FIELDS:
        new_user[str(field)] = user[field] if field in user else None
    return new_user

class OutputWriterCSV:
    def __init__(self, fd=sys.stdout):
        self._writer = csv.writer(fd, lineterminator='\n')

    def __enter__(self):
        return self

    def __exit__(self, *args):
        pass

    def write_mutual_friends(self, friend_list):
        for user in friend_list:
            user = _filter_user_fields(user)
            self._writer.writerow(user.values())

class OutputWriterJSON:
    def __init__(self, fd=sys.stdout):
        self._fd = fd
        self._array = []

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self._fd.write(json.dumps(self._array, indent=3, ensure_ascii=False))
        self._fd.write('\n')

    def write_mutual_friends(self, friend_list):
        for user in friend_list:
            self._array.append(_filter_user_fields(user))

class OutputFormat(Enum):
    CSV = 'csv'
    JSON = 'json'<commit_msg>mutual_friends.py: refactoring<commit_after># Copyright 2015 <NAME> <<EMAIL>>
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.

import argparse
from collections import OrderedDict
import csv
from enum import Enum
import json
import sys

from vk.api import API, Language
from vk.user import UserField

_OUTPUT_USER_FIELDS = UserField.UID, UserField.FIRST_NAME, UserField.LAST_NAME

def _query_friend_list(api, user):
    return api.friends_get(user.get_uid(), fields=_OUTPUT_USER_FIELDS)

def _filter_user_fields(user):
    new_user = OrderedDict()
    for field in _OUTPUT_USER_FIELDS:
        new_user[str(field)] = user[field] if field in user else None
    return new_user

class OutputWriterCSV:
    def __init__(self, fd=sys.stdout):
        self._writer = csv.writer(fd, lineterminator='\n')

    def __enter__(self):
        return self

    def __exit__(self, *args):
        pass

    def write_mutual_friends(self, friend_list):
        for user in friend_list:
            user = _filter_user_fields(user)
            self._writer.writerow(user.values())

class OutputWriterJSON:
    def __init__(self, fd=sys.stdout):
        self._fd = fd
        self._arr = []

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self._fd.write(json.dumps(self._arr, indent=3, ensure_ascii=False))
        self._fd.write('\n')

    def write_mutual_friends(self, friend_list):
        for user in friend_list:
            self._arr.append(_filter_user_fields(user))

class OutputFormat(Enum):
    CSV = 'csv'
    JSON = 'json'
{'fraction_non_alphanumeric': 0.09475996234703483, 'fraction_numerical': 0.0031377470975839346, 'mean_word_length': 3.3374149659863948, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1163852', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1005, 'n_words': 264}