Ejemplo n.º 1
0
def abortTransaction(message, sender_id, transaction_state):
    pool, con, curs = cnnct()

    if message.lower() == '!abort':
        init_abort_transaction_script = open(
            os.getcwd() + '//sql_scripts//init_abort_transaction.sql').read()
        curs.execute(
            init_abort_transaction_script, {
                "previous_transaction_state": transaction_state,
                "sender_id": sender_id
            })

    elif transaction_state == 5:
        if message == 'y':
            confirm_abort_transaction_script = open(
                os.getcwd() +
                '//sql_scripts//confirm_abort_transaction.sql').read()
            curs.execute(confirm_abort_transaction_script,
                         {"sender_id": sender_id})

        elif message == 'n':
            stop_abort_transaction_script = open(
                os.getcwd() +
                '//sql_scripts//stop_abort_transaction.sql').read()
            curs.execute(stop_abort_transaction_script,
                         {"sender_id": sender_id})

    dscnnct(pool, con, curs)
Ejemplo n.º 2
0
def lastTenTransactions(sender_id):
    get_last_ten_transactions_script = open(
        os.getcwd() + '//sql_scripts//get_last_ten_transactions.sql').read()
    pool, con, curs = cnnct()
    curs.execute(get_last_ten_transactions_script, {"sender_id": sender_id})
    spending_data = curs.fetchmany(10)
    dscnnct(pool, con, curs)
    return spending_data
Ejemplo n.º 3
0
def commitTransaction(sender_id):
    commit_transaction_script = open(
        os.getcwd() + '//sql_scripts//commit_transaction.sql').read()
    delete_completed_transaction_script = open(
        os.getcwd() +
        '//sql_scripts//delete_completed_transaction.sql').read()
    pool, con, curs = cnnct()
    curs.execute(commit_transaction_script, {"sender_id": sender_id})
    curs.execute(delete_completed_transaction_script, {"sender_id": sender_id})
    dscnnct(pool, con, curs)
Ejemplo n.º 4
0
def checkCreds(sender_id):
    check_creds_script = open(os.getcwd() +
                              '//sql_scripts//check_creds.sql').read()
    pool, con, curs = cnnct()
    curs.execute(check_creds_script, {"sender_id": sender_id})
    creds_exist = curs.fetchone()[0]
    dscnnct(pool, con, curs)
    if creds_exist:
        return True
    return False
Ejemplo n.º 5
0
def getTransactionState(sender_id):
    get_transaction_state_script = open(
        os.getcwd() + '//sql_scripts//get_transaction_state.sql').read()
    pool, con, curs = cnnct()
    curs.execute(get_transaction_state_script, {"sender_id": sender_id})
    query_result = curs.fetchone()
    dscnnct(pool, con, curs)
    if query_result is None:
        return None
    transaction_state = query_result[0]
    return transaction_state
Ejemplo n.º 6
0
def deleteUser(sender_id, state):
    pool, con, curs = cnnct()
    if state == 1:
        init_user_deletion_script = open(
            os.getcwd() + '//sql_scripts//init_user_deletion.sql').read()
        curs.execute(init_user_deletion_script, {"sender_id": sender_id})
    elif state == 2:
        delete_user_script = open(os.getcwd() +
                                  '//sql_scripts//delete_user.sql').read()
        curs.execute(delete_user_script, {"sender_id": sender_id})
    else:
        abort_user_deletion_script = open(
            os.getcwd() + '//sql_scripts//abort_user_deletion.sql').read()
        curs.execute(abort_user_deletion_script, {"sender_id": sender_id})

    dscnnct(pool, con, curs)
Ejemplo n.º 7
0
def updateTransaction(sender_id, message, previous_transaction_state):
    pool, con, curs = cnnct()

    if previous_transaction_state == 0:
        add_product_service_script = open(
            os.getcwd() + '//sql_scripts//add_product_service.sql').read()
        curs.execute(add_product_service_script, {
            "prod_serv": message,
            "sender_id": sender_id
        })

    elif previous_transaction_state == 1:
        add_price_script = open(os.getcwd() +
                                '//sql_scripts//add_price.sql').read()
        curs.execute(add_price_script, {
            "price": float(message),
            "sender_id": sender_id
        })

    elif previous_transaction_state == 2:
        add_vendor_script = open(os.getcwd() +
                                 '//sql_scripts//add_vendor.sql').read()
        curs.execute(add_vendor_script, {
            "vendor": message,
            "sender_id": sender_id
        })

    elif previous_transaction_state == 3:
        add_category_script = open(os.getcwd() +
                                   '//sql_scripts//add_category.sql').read()
        curs.execute(add_category_script, {
            "category": message,
            "sender_id": sender_id
        })

    dscnnct(pool, con, curs)
    transaction_state = getTransactionState(sender_id)
    if transaction_state == 4:
        commitTransaction(sender_id)
Ejemplo n.º 8
0
def createNewTransaction(sender_id):
    create_new_transaction_script = open(
        os.getcwd() + '//sql_scripts//create_new_transaction.sql').read()
    pool, con, curs = cnnct()
    curs.execute(create_new_transaction_script, {"sender_id": sender_id})
    dscnnct(pool, con, curs)
Ejemplo n.º 9
0
def deleteNewSender(sender_id):
    delete_new_sender_script = open(
        os.getcwd() + '//sql_scripts//delete_new_sender.sql').read()
    pool, con, curs = cnnct()
    curs.execute(delete_new_sender_script, {"sender_id": sender_id})
    dscnnct(pool, con, curs)
Ejemplo n.º 10
0
def createAccount(sender_id):
    create_account_script = open(os.getcwd() +
                                 '//sql_scripts//create_account.sql').read()
    pool, con, curs = cnnct()
    curs.execute(create_account_script, {"sender_id": sender_id})
    dscnnct(pool, con, curs)