import sqlite3
from sqlite3 import Error
from createDbTable import create_connection

def update_task(conn, address, inIP):
    """
    update IP address of associated ETH address 
    :param IP:
    :param Changed:
    :return: project id
    """
    cur = conn.cursor()
    if inIP == '127.0.0.1':
    	cur.execute("UPDATE Addresses SET IP = ?, Changed = ? WHERE EthAddress = ?",(inIP,0,address))
    else:
    	cur.execute("UPDATE Addresses SET IP = ?, Changed = ? WHERE EthAddress = ?",(inIP,1,address))
    conn.commit()


def main():
    database = r"/home/nicoski/Desktop/dockChain/files/permitted.db"
    inputAddress = str(input("Enter an Ethereum Address: "))
    inputIP = input("Enter the new IP address: ")
    # create a database connection
    conn = create_connection(database)
    with conn:
        update_task(conn,inputAddress,inputIP)


if __name__ == '__main__':
    main()
