<commit_before># -*- coding: utf-8 -*-
"""
A database class to save and access parsed data
"""

import abc, os
import sqlite3 as lite
from magic import logging, DEBUG_DATABASE, DEBUG_TABLE, FILEDB_DIR

logger = logging.getLogger('database')

# Check dir and create
if not os.path.exists(FILEDB_DIR):
    try:
        os.makedirs(FILEDB_DIR)
    except OSError:
        logger.error("Failed to create dir '" + FILEDB_DIR + "'")

class db(object):
    """Generic db abstraction"""

    dbname = DEBUG_DATABASE
    connection = None

    def __init__(self, database):
        # Init
        super(db, self).__init__()
        # Arguments
        if database != None:
            self.dbname = database
        # Db connection
        logger.debug("Db istance")
        self.connect()

    @abc.abstractmethod
    def connect(self):
        """ Abstract connection """
        return

class dblite(db):
    """ Implementation of database via sqlite3 library """

    cursor = None
    sqlfile = 'noname'

    def __init__(self, database):
        # Parent constructor
        super(dblite, self).__init__(database)

    def connect(self):

        # Operations
        self.sqlfile = FILEDB_DIR + '/' + self.dbname + '.db'

        # connect
        try:
            self.connection = lite.connect(self.sqlfile)
            logger.info("Db file: " + self.sqlfile)
            self.cursor = self.connection.cursor()
        except lite.Error, e:
            raise BaseException("No sql lite connection", e)
        finally:
            logger.info("Connected")
            print self.connection
<commit_msg>Making db compatible with python3<commit_after># -*- coding: utf-8 -*-
"""
A database class to save and access parsed data
"""

import abc, os
import sqlite3 as lite
from magic import logging, DEBUG_DATABASE, DEBUG_TABLE, FILEDB_DIR

logger = logging.getLogger('database')

# Check dir and create
if not os.path.exists(FILEDB_DIR):
    try:
        os.makedirs(FILEDB_DIR)
    except OSError:
        logger.error("Failed to create dir '" + FILEDB_DIR + "'")

class db(object):
    """Generic db abstraction"""

    dbname = DEBUG_DATABASE
    tablename = DEBUG_TABLE
    connection = None

    def __init__(self, database):
        # Init
        super(db, self).__init__()
        # Arguments
        if database != None:
            self.dbname = database
        # Db connection
        logger.debug("Db istance")
        self.connect()

    @abc.abstractmethod
    def connect(self):
        """ Abstract connection """
        return

class dblite(db):
    """ Implementation of database via sqlite3 library """

    cursor = None
    sqlfile = 'noname'

    def __init__(self, database):
        # Parent constructor
        super(dblite, self).__init__(database)

    def connect(self):

        # Operations
        self.sqlfile = FILEDB_DIR + '/' + self.dbname + '.db'

        # connect
        try:
            self.connection = lite.connect(self.sqlfile)
            logger.info("Db file: " + self.sqlfile)
            self.cursor = self.connection.cursor()
        except lite.Error as e:
            raise BaseException("No sql lite connection", e)
        finally:
            logger.info("Connected: " + self.connection.__repr__())

    def get_content(self):
        # Query
        query = "SELECT * FROM " + self.tablename
        self.cursor.execute(query)
        for i in self.cursor.fetchall():
            #DEBUG
            print(i)

{'fraction_non_alphanumeric': 0.10892805547529616, 'fraction_numerical': 0.0020225368390638545, 'mean_word_length': 2.235514018691589, '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': '1241774', 'n_tokens_mistral': 1016, 'n_tokens_neox': 997, 'n_words': 268}