<commit_before>__author__ = 'ian'

from couchdb import ResourceNotFound, Server
from couchdb.mapping import Document
from json import load
from os.path import abspath, dirname, join


def init_db(app):
    dbname = app.config.get("DB_NAME") or "blackbook"
    server = Server(app.config.get("COUCHDB_URI") or "http://localhost:5984")  # default to couch default uri

    # Create database_old if it doesn't exist
    try:
        db = server[dbname]
    except ResourceNotFound:
        db = server.create(dbname)

    # Load in schema file
    with open(join(join(dirname(abspath(__file__)), "js"), "{db}.json".format(db=dbname))) as schema_file:
        schema = load(schema_file)

    # Update design docs and api specs according to schema file
    for doc in schema:
        d = Document.load(db, doc.get("_id"))
        if d:
            for k, v in doc.items():
                if k in d:
                    if d[k] != v:
                        d[k] = v
                else:
                    d[k] = v
            d.store(db)

    return db<commit_msg>* fixed a comment that was auto-typoed by old refactor<commit_after>__author__ = 'ian'

from couchdb import ResourceNotFound, Server
from couchdb.mapping import Document
from json import load
from os.path import abspath, dirname, join


def init_db(app):
    dbname = app.config.get("DB_NAME") or "blackbook"
    server = Server(app.config.get("COUCHDB_URI") or "http://localhost:5984")  # default to couch default uri

    # Create database if it doesn't exist
    try:
        db = server[dbname]
    except ResourceNotFound:
        db = server.create(dbname)

    # Load in schema file
    with open(join(join(dirname(abspath(__file__)), "js"), "{db}.json".format(db=dbname))) as schema_file:
        schema = load(schema_file)

    # Update design docs and api specs according to schema file
    for doc in schema:
        d = Document.load(db, doc.get("_id"))
        if d:
            for k, v in doc.items():
                if k in d:
                    if d[k] != v:
                        d[k] = v
                else:
                    d[k] = v
            d.store(db)

    return db
{'fraction_non_alphanumeric': 0.10448451225150254, 'fraction_numerical': 0.0036985668053629217, 'mean_word_length': 2.168374816983895, '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': '4197970', 'n_tokens_mistral': 673, 'n_tokens_neox': 642, 'n_words': 208}