<commit_before>import configparser

from pymongo import MongoClient


class MongoDataSource:
    def __init__(self):
        config = configparser.ConfigParser()
        config.read('../songci.conf')
        if 'mongo' not in config:
            raise KeyError('Config section [mongo] not found.')
        config_mongo = config['mongo']

        self._client = MongoClient(config_mongo['MONGO_URI'])
        self._db = self._client[config_mongo['MONGO_DB_SONGCI']]

    def find(self, collection_name, *args, **kwargs):
        collection = self._db[collection_name]
        return (document for document in collection.find(*args, **kwargs))

    def save(self, collection_name, _filter, update):
        self._db[collection_name].update_one(_filter, {'$set': update}, upsert=True)

    def create_index(self, col_name, index_field, **kwargs):
        self._db[col_name].create_index(index_field, name=index_field + '_index', **kwargs)
<commit_msg>format data_source.py<commit_after>import configparser

from pymongo import MongoClient


class MongoDataSource:
    def __init__(self):
        config = configparser.ConfigParser()
        config.read('../songci.conf')
        if 'mongo' not in config:
            raise KeyError('Config section [mongo] not found.')
        config_mongo = config['mongo']

        self._client = MongoClient(config_mongo['MONGO_URI'])
        self._db = self._client[config_mongo['MONGO_DB_SONGCI']]

    def find(self, collection_name, *args, **kwargs):
        return self._db[collection_name].find(*args, **kwargs)

    def save(self, collection_name, _filter, update):
        return self._db[collection_name].update_one(_filter, {'$set': update}, upsert=True)

    def create_index(self, collection_name, index_field, **kwargs):
        return self._db[collection_name].create_index(index_field, name=index_field + '_index', **kwargs)

{'fraction_non_alphanumeric': 0.12386545648691938, 'fraction_numerical': 0.0, 'mean_word_length': 3.829896907216495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2453503', 'n_tokens_mistral': 577, 'n_tokens_neox': 554, 'n_words': 121}