<commit_before>#!/usr/env python
# -*- coding: utf-8 -*-
import os
import subprocess

import MySQLdb as mysql

BASEPATH = os.path.dirname(__file__)


class DBConnection(object):
    """Handle DB connectivity."""
    def __init__(self):
        self.read_config()
        self.connect()

    def read_config(self):
        configf = open(BASEPATH + '/config.js', 'rb')
        self.config = {}
        for line in configf:
            if line.find('host') > -1:
                self.config['host'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('user') > -1:
                self.config['user'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('password') > -1:
                self.config['password'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('database') > -1:
                self.config['database'] = line.translate(None, '"\r\n, ').split(':')[1]
        configf.close()

    def connect(self):
        self.conn = mysql.connect(
            host=self.config['host'],
            db=self.config['database'],
            user=self.config['user'],
            passwd=self.config['password']
        )
        self.cursor = self.conn.cursor(mysql.cursors.DictCursor)

    def close(self):
        self.conn.commit()<commit_msg>Fix reading of db config from Python utils<commit_after>#!/usr/env python
# -*- coding: utf-8 -*-
import os
import subprocess

import MySQLdb as mysql

BASEPATH = os.path.dirname(__file__)


class DBConnection(object):
    """Handle DB connectivity."""
    def __init__(self):
        self.read_config()
        self.connect()

    def read_config(self):
        configf = open(BASEPATH + '/config.js', 'rb')
        self.config = {}
        db_config = False
        for line in configf:
            if not db_config:
                if line.find('config.db') > -1:
                    db_config = True
                continue
            if line.find('host') > -1:
                self.config['host'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('user') > -1:
                self.config['user'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('password') > -1:
                self.config['password'] = line.translate(None, '"\r\n, ').split(':')[1]
            elif line.find('database') > -1:
                self.config['database'] = line.translate(None, '"\r\n, ').split(':')[1]
                break
        configf.close()

    def connect(self):
        self.conn = mysql.connect(
            host=self.config['host'],
            db=self.config['database'],
            user=self.config['user'],
            passwd=self.config['password']
        )
        self.cursor = self.conn.cursor(mysql.cursors.DictCursor)

    def close(self):
        self.conn.commit()
{'fraction_non_alphanumeric': 0.17305663032008442, 'fraction_numerical': 0.006683081252198382, 'mean_word_length': 1.9936842105263157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7167763', 'n_tokens_mistral': 885, 'n_tokens_neox': 857, 'n_words': 170}