Esempio n. 1
0
def update_industry_info(data):
    with connection.cursor() as cursor:
        cursor.execute("Select * from Ind_Info where emailid = %s",
                       [data["emailid"]])

        row = cursor.fetchone()
        # Driver acc not present in database, SANITY CHECK
        if row == None:
            print("Something Weird Happened Sanity Check")
            return False

        cmd = "Update Ind_Info set "
        for key in data.keys():
            if key != "emailid":
                cmd += str(key) + " = " + '"' + str(data[key]) + '"' + ","
        cmd = cmd[0:-1]
        cmd += " where emailid = " + '"' + str(data["emailid"]) + '"'

        if DEBUG:
            print(cmd)

        client_num = getClientNum(data["emailid"])
        server.pushData(client_num, cmd)

        cursor.execute(cmd)
        return True
Esempio n. 2
0
def add_driver_info(data):
    with connection.cursor() as cursor:
        cursor.execute("Select * from Driver_Info where emailid = %s",
                       [data["emailid"]])

        row = cursor.fetchone()
        # Driver acc already present in database, SANITY CHECK
        if row != None:
            return False


        cmd = 'Insert Into Driver_Info Values ("%s", "%s", "%s", "%s", "%s", "%s", "%s")' % \
            (data["emailid"], data["fname"], data["lname"], data["phone_num"],
            data["license_num"], data["start_loc"], data["end_loc"])
        client_num = getClientNum(data["emailid"])
        server.pushData(client_num, cmd)

        cursor.execute(
            "Insert Into Driver_Info Values (%s, %s, %s, %s, %s, %s, %s)", [
                data["emailid"], data["fname"], data["lname"],
                data["phone_num"], data["license_num"], data["start_loc"],
                data["end_loc"]
            ])

        return True
Esempio n. 3
0
def delete_user_account(data):
    with connection.cursor() as cursor:
        cursor.execute("Select * from User_Accounts where emailid = %s",
                       [data["emailid"]])

        row = cursor.fetchone()
        # User not present in database, SANITY CHECK
        if row == None:
            print("Sanity CHECK user not present in delete data")
            return False

        cmd = 'Delete from User_Accounts where emailid = "%s"' % data["emailid"]
        client_num = getClientNum(data["emailid"])
        server.pushData(client_num, cmd)
        cursor.execute("Delete from User_Accounts where emailid = %s",
                       [data["emailid"]])
        return True
Esempio n. 4
0
def get_industry_info(data):
    with connection.cursor() as cursor:
        cursor.execute("Select * from Ind_Info where emailid = %s",
                       [data["emailid"]])

        row = cursor.fetchone()
        # Driver acc not present in database, SANITY CHECK
        if row == None:
            print("SANITY CHECK Driver info not present")

            cmd = 'Insert Into Ind_Info Values ("%s", "%s", "%s", "%s", "%s")' % \
                (data["emailid"], "", "", "", "")

            client_num = getClientNum(data["emailid"])
            server.pushData(client_num, cmd)

            cursor.execute("Insert Into Ind_Info Values (%s, %s, %s, %s, %s)",
                           [data["emailid"], "", "", "", ""])
            return True, [data["emailid"], "", "", "", ""]

        return True, row
Esempio n. 5
0
def add_user_account(data):
    with connection.cursor() as cursor:

        if DEBUG:
            print(data)

        cursor.execute("Select * from User_Accounts where emailid = %s",
                       [data["emailid"]])

        row = cursor.fetchone()
        # User Account already present
        if row != None:
            return False

        cmd = 'Insert Into User_Accounts Values ("%s", "%s", "%s")' % \
            (data["emailid"], data["passwd"], data["type_of_acc"])
        client_num = getClientNum(data["emailid"])
        server.pushData(client_num, cmd)
        cursor.execute("Insert Into User_Accounts Values (%s, %s, %s)",
                       [data["emailid"], data["passwd"], data["type_of_acc"]])

        return True
Esempio n. 6
0
def add_data(num):

    global industries

    with connection.cursor() as cursor:
        # Input driver info
        for i in range(num):

            phone_num = gen_phone_num()
            license_num = gen_phone_num()
            start_loc = random.choice(cities)
            end_loc = random.choice(cities)

            while True:
                fname = names.get_first_name()
                lname = names.get_last_name()
                email = fname + "." + lname + "@" + str(get_one_random_domain(domains))

                cursor.execute("Select * from User_Accounts where emailid = %s", [email])
                row = cursor.fetchone()
                if row == None:
                    break

            # Add account to user account
            cmd = 'Insert into User_Accounts values ("%s", "%s", "%s")' % \
            (email, "ananmay", "driver")
            client_num = getClientNum(email)
            server.pushData(client_num, cmd)

            cursor.execute("Insert into User_Accounts values (%s, %s, %s)",
            [email, "ananmay", "driver"])

            # Add Driver Info
            cmd = 'Insert into Driver_Info values ("%s", "%s", "%s", "%s", "%s", "%s", "%s")' % \
            (email, fname, lname, phone_num, license_num, start_loc, end_loc)
            server.pushData(client_num, cmd)

            cursor.execute("Insert into Driver_Info values (%s, %s, %s, %s, %s, %s, %s)",
            [email, fname, lname, phone_num, license_num, start_loc, end_loc])

        # Input Industry Info
        for i in range(num):

            ind_name = random.choice(industries)

            while True:
                fname = names.get_first_name()
                lname = names.get_last_name()
                email = fname + "." + lname + "@" + str(get_one_random_domain(domains))

                cursor.execute("Select * from User_Accounts where emailid = %s", [email])
                row = cursor.fetchone()
                if row == None:
                    break

            # Add account to user account
            cmd = 'Insert into User_Accounts values ("%s", "%s", "%s")' % \
            (email, "ananmay", "industry")
            client_num = getClientNum(email)
            server.pushData(client_num, cmd)

            cursor.execute("Insert into User_Accounts values (%s, %s, %s)",
            [email, "ananmay", "industry"])

            # Add Industry Info
            cmd = 'Insert into Ind_Info values ("%s", "%s", "%s", "%s")' % \
                           (email, fname, lname, ind_name)
            server.pushData(client_num, cmd)
            cursor.execute("Insert into Ind_Info values (%s, %s, %s, %s)",
                           [email, fname, lname, ind_name])

        # Input Trips Info
        for i in range(num):
            trip_id = gen_random_trip_id()
            rating_from_driver = gen_rating()
            rating_from_ind = gen_rating_with_arg(rating_from_driver)

            cursor.execute("SELECT emailid FROM Driver_Info")
            drivers = cursor.fetchall()
            d_len = len(drivers)
            cursor.execute("SELECT emailid FROM Ind_Info")
            industries = cursor.fetchall()
            i_len = len(industries)

            cursor.execute("Insert Into Trips values (%s, %s, %s, %s, %s, %s, %s, %s)",
            [trip_id, '1', drivers[random.randint(0,d_len-1)][0],
             industries[random.randint(0, i_len-1)][0], str(rating_from_driver),
             str(rating_from_ind), "alright", "okay"])