<commit_before>import setupMoney, os, sys, sqlite3, csv
from optparse import OptionParser
from os import listdir
from os.path import isfile, join

__author__ = "Tannerism"
__date__ = "$Jun 27, 2015 7:45:55 PM$"

dbConn = ""
dbCur = ""
allCategories = []

def readInCsv(csvFilePath):
    rows = []
    with open(csvFilePath, 'rb') as csvFile:
        reader = csv.reader(csvFile, delimiter=",")
        header = None
        rowLen = 0
        for row in reader:
            if header == None:
                header = row
                rowLen = len(header)
            else:
                while len(row) < rowLen:
                    row.append('')
                rows.append(row)
    return rows

def formatTransactionForPrint(trans):
    transStr = ""
    transStr = str(trans[1]) + "/" + str(trans[2]) + "/" + str(trans[0]) + "\t"
    transStr += ' '.join(trans[4].split())+ "\t"
    transStr += (("-" + str(trans[5])) if trans[5] != 0 else trans[6])
    return transStr

def formatCategoryOptions():
    categStr = ""
    for i in range(len(allCategories)):
        categStr += "(" + str(i) + ") - "
        categStr += allCategories[i][(len(allCategories[i])-1)] + ";  "
    return categStr

def categorizeTransaction(trans):
    isMatched = False
    for match in dbCur.execute("SELECT * FROM matches"):
        if trans[4].lower().find(match[0].lower()) > -1:
            trans[7] = match[1]
            trans[8] = match[2]
            isMatched = True
            break
    if isMatched == False:
        inputStr = '\nPlease enter the number corresponding to the the category for this entry: '
        inputStr += "\n----------  TRANSACTION:  ----------\n"
        inputStr += formatTransactionForPrint(trans) 
        inputStr += "\n----------  CATEGORIES:  ----------\n"
        inputStr += formatCategoryOptions() 
        inputStr += "\n:"
        categId = input(inputStr)
        try:
            if int(categId) < len(allCategories):
                should="setup the categ id and sub categ id and update the csv and db"
        except:
            categId = input("Please enter a number corresponding with the category. If the options were (0) - Gas  (1) - Food and it was gas, you would enter 0\n:")
    return trans

def processBankStatement(data, schema):
    global dbConn, dbCur
    entries = []
    for entry in data:
        curEntry = []
        selEntry = []<commit_msg>Setup the database to be updated based on what the user inputs for the category on a given transaction. Fixed the display when asking the user for input so it shows the correct amount for the transaction with a - sign when appropriate (#5)<commit_after>import setupMoney, os, sys, sqlite3, csv
from optparse import OptionParser
from os import listdir
from os.path import isfile, join

__author__ = "Tannerism"
__date__ = "$Jun 27, 2015 7:45:55 PM$"

dbConn = ""
dbCur = ""
allCategories = []

def readInCsv(csvFilePath):
    rows = []
    with open(csvFilePath, 'rb') as csvFile:
        reader = csv.reader(csvFile, delimiter=",")
        header = None
        rowLen = 0
        for row in reader:
            if header == None:
                header = row
                rowLen = len(header)
            else:
                while len(row) < rowLen:
                    row.append('')
                rows.append(row)
    return rows

def formatTransactionForPrint(trans):
    transStr = ""
    transStr = str(trans[1]) + "/" + str(trans[2]) + "/" + str(trans[0]) + "\t"
    transStr += ' '.join(trans[4].split())+ "\t"
    if float(trans[5]) > 0:
        transStr += "-" + trans[5]
    else:
        transStr += trans[6]
#    transStr += (("-" + str(trans[5])) if trans[5] > 0 else trans[6])
    return transStr

def formatCategoryOptions():
    categStr = ""
    for i in range(len(allCategories)):
        categStr += "(" + str(i) + ") - "
        categStr += allCategories[i][(len(allCategories[i])-1)] + ";  "
    return categStr

def categorizeTransaction(trans):
    isMatched = False
    for match in dbCur.execute("SELECT * FROM matches"):
        if trans[4].lower().find(match[0].lower()) > -1:
            trans[7] = match[1]
            trans[8] = match[2]
            isMatched = True
            break
    if isMatched == False:
        inputStr = '\nPlease enter the number corresponding to the the category for this entry: '
        inputStr += "\n----------  TRANSACTION:  ----------\n"
        inputStr += formatTransactionForPrint(trans) 
        inputStr += "\n----------  CATEGORIES:  ----------\n"
        inputStr += formatCategoryOptions() 
        inputStr += "\n:"
        categId = input(inputStr)
        try:
            if int(categId) < len(allCategories):
                if len(allCategories[categId]) == 2:
                    trans[7] = allCategories[categId][0]
                    trans[8] = ''
                else:
                    trans[7] = allCategories[categId][1]
                    trans[8] = allCategories[categId][0]
        except:
            categId = input("Please enter a number corresponding with the category. If the options were (0) - Gas  (1) - Food and it was gas, you would enter 0\n:")
    return trans

def processBankStatement(data, schema):
    global dbConn, dbCur
    entries = []
    for entry in data:
        curEntry = []
        selEntry = []
{'fraction_non_alphanumeric': 0.13845575803118543, 'fraction_numerical': 0.014465526958482059, 'mean_word_length': 2.0792365529207633, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '67925', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1555, 'n_words': 463}