<commit_before>#! /usr/bin/env python
# --*-- coding:utf-8 --*--

import MySQLdb
from ext.util import *
from config.setting import *


class Dber(object):

    def __init__(self):
        self.host = database.get('host')
        self.port = database.get('port')
        self.user = database.get('user')
        self.password = database.get('password')
        self.dbname = database.get('databasename')
        self.conn = None
        self.setConnection()

    def setConnection(self):
        try:
            self.conn = MySQLdb.Connect(host=self.host,user=self.user,passwd=<PASSWORD>,db=self.dbname,port=self.port,charset='utf8')
            self.cur = self.conn.cursor()
        except Exception as ex:
            traceback.print_exc()

    def syncDruidData(self, druidresult):
        if isinstance(druidresult, list):
            for result in druidresult:
                print result
                insertSql = "insert into {0} values {1}".format(database.get('tablename'), unicode2str(result))
                print insertSql
                self.insertRecord(insertSql)
                break
        self.setCommit()

    def insertRecord(self, sql):
        if self.conn:
            self.cur.execute(sql)

    def setCommit(self):
        self.conn.commit()

    def getRecord(self, sql):
        if self.conn:
            executeStatus = self.cur.execute(sql)
            return self.cur.fetchall()
<commit_msg>update databaser class<commit_after>#! /usr/bin/env python
# --*-- coding:utf-8 --*--

import MySQLdb
from ext.util import *
from config.setting import *


class Dber(object):

    def __init__(self):
        self.host = database.get('host')
        self.port = database.get('port')
        self.user = database.get('user')
        self.password = database.get('password')
        self.dbname = database.get('databasename')
        self.conn = None
        self.setConnection()

    def setConnection(self):
        try:
            self.conn = MySQLdb.Connect(host=self.host,user=self.user,passwd=<PASSWORD>,db=self.dbname,port=self.port,charset='utf8')
            self.cur = self.conn.cursor()
        except Exception as ex:
            traceback.print_exc()

    def syncDruidData(self, druidresult):
        if isinstance(druidresult, list):
            for result in druidresult:
                insertSql = "insert into {0} values {1}".format(database.get('tablename'), unicode2str(result))
                self.insertRecord(insertSql)
        self.setColseCommit()

    def insertRecord(self, sql):
        if self.conn:
            self.cur.execute(sql)

    def setColseCommit(self):
        self.cur.commit()
        self.conn.commit()
        self.conn.close()

    def getRecord(self, sql):
        if self.conn:
            executeStatus = self.cur.execute(sql)
            return self.cur.fetchall()

{'fraction_non_alphanumeric': 0.12517580872011252, 'fraction_numerical': 0.0035161744022503515, 'mean_word_length': 2.211060948081264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1253599', 'n_tokens_mistral': 864, 'n_tokens_neox': 838, 'n_words': 165}