Esempio n. 1
0
def createdb(dtt):
    """
    Creates database and tables if the database does not exist. Creates it in the same place as the bank statement
    (csv) files exist as a hidden file
    :param dtt: List of default transaction types
    :return:
    """
    dbname = ".TransactionDB.sqlite"
    path2dir = rf.getcsvpath()
    path2db = path2dir + dbname

    if os.path.exists(path2db):
        print "check - db exists"
        return
    else:

        conn = connect()
        c = conn.cursor()

        c.execute("CREATE TABLE TransactionType(id INTEGER PRIMARY KEY, type TEXT, UNIQUE(type))")

        c.execute('''CREATE TABLE TransactionPlace(id INTEGER PRIMARY KEY, tt_id INTEGER, description TEXT,
                        FOREIGN KEY(tt_id) REFERENCES TransactionType(id))''')

        c.execute('''CREATE TABLE TransactionInfo(id INTEGER PRIMARY KEY, tt_id INTEGER, tp_id INTEGER, date TEXT,
                        amount REAL, balance REAL, FOREIGN KEY(tt_id) REFERENCES TransactionType(id),
                        FOREIGN KEY(tp_id) REFERENCES TransactionPlace(id))''')
        conn.commit()
        conn.close()

        print "check - db and tables created"

        add_default_tt(dtt)

        return
Esempio n. 2
0
def connect():
    """
    Connects to database
    :return: connection to sqlite database
    """
    dbname = ".TransactionDB.sqlite"
    path2dir = rf.getcsvpath()
    path2db = path2dir + dbname

    return sqlite3.connect(path2db)
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#

import readfiles as rf
import dataclean as dclean
import dbcalls as dbc
import infovisualisation as iv

if __name__ == '__main__':
    path2csv = rf.getcsvpath()
    dtt = ["Supermarket", "ATM", "Kiosk", "Shopping", "Night Out", "Eating Out", "Transport", "Money In",
           "House", "Rent and Bills", "Hobbies", "Misc"]  # List of default transaction types

    dbc.createdb(dtt)

    csvfiles = rf.findcsvfiles(path2csv)  # List of paths to CSV files
    translist = rf.readcsvfiles(csvfiles)  # List of transactions from all CSV files
    cleanlist = dclean.formatlist(translist)  # Cleans up the transaction data

    dbc.add2db(cleanlist)
    iv.generalview()
    iv.dayview()