<commit_before>import karmaconfig
from pymongo import MongoClient
from passlib.hash import sha256_crypt # http://pythonhosted.org/passlib/
from time import gmtime, strftime

client = MongoClient(karmaconfig.URI)
db = client.karmaconfig.DBNAME

def getNow():
    return strftime("%Y-%m-%d %H:%M:%S", gmtime())

#for troubleshooting
def makeObject(cursor):
    theObject = dict((cursor, record) for record in cursor)
    return theObject

def insertUser(user):
    # db['user'].ensure_index("email",unique=1,background=1)
    # db['user'].ensure_index("username",unique=1,background=1)
    db['user'].insert({"email":user.email, "hash": setHash(user), "karma":user.karma, "username": user.username})

#May want to consider changing $set to '$inc' 
def addKarma(email, karma):
    db['user'].update({"email":email},{ "$set": {"karma": karma}})

def updateThanker(email, thanker):
    db['user'].update({"email":email},{"$push":{"thankers":{getNow():thanker}}})

def validateUser(password,email):
    return verifyPassword(password,getHash(email))

def verifyPassword(password,pass_hash):
    return sha256_crypt.verify(password,pass_hash)

def getHash(email):
    cursor = db['user'].find_one({"email":email}, fields ={"hash":1})
    return cursor['hash'] <commit_msg>fixing config<commit_after>import karmaconfig
from pymongo import MongoClient
from passlib.hash import sha256_crypt # http://pythonhosted.org/passlib/
from time import gmtime, strftime

client = MongoClient(karmaconfig.URI)
db = client[karmaconfig.DBNAME]

def getNow():
    return strftime("%Y-%m-%d %H:%M:%S", gmtime())

#for troubleshooting
def makeObject(cursor):
    theObject = dict((cursor, record) for record in cursor)
    return theObject

def insertUser(user):
    # db['user'].ensure_index("email",unique=1,background=1)
    # db['user'].ensure_index("username",unique=1,background=1)
    db['user'].insert({"email":user.email, "hash": setHash(user), "karma":user.karma, "username": user.username})

#May want to consider changing $set to '$inc' 
def addKarma(email, karma):
    db['user'].update({"email":email},{ "$set": {"karma": karma}})

def updateThanker(email, thanker):
    db['user'].update({"email":email},{"$push":{"thankers":{getNow():thanker}}})

def validateUser(password,email):
    return verifyPassword(password,getHash(email))

def verifyPassword(password,pass_hash):
    return sha256_crypt.verify(password,pass_hash)

def getHash(email):
    cursor = db['user'].find_one({"email":email}, fields ={"hash":1})
    return cursor['hash'] 
{'fraction_non_alphanumeric': 0.17344922955353614, 'fraction_numerical': 0.00869221651521138, 'mean_word_length': 6.425219941348973, 'pattern_counts': {'":': 24, '<': 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': '1096356', 'n_tokens_mistral': 857, 'n_tokens_neox': 822, 'n_words': 169}