Beispiel #1
0
def startExpedition(userID, expeditionID):

    # Get the Expedition ID.
    response = getExpeditionByID(expeditionID)
    if not response[0] == 0:
        print("ERROR: Expedition ID does not exist.")
        return False

    expedition_obj = response[1]
    # Get the start and end timings (start_timing, end_timing)
    timings = getTiming(expedition_obj.TimeTaken)

    # Get a randomized HToken value. +50 or -50)
    randomizedHToken = randomizeHToken(expedition_obj.HToken)

    # Insert record into myUserExpedition table.
    values = [
        userID, 'Y', expeditionID, timings[0], timings[1], randomizedHToken
    ]
    sql_statement = "INSERT INTO myuserexpedition (userId, isOngoing, expeditionId, startTime, endTime, hTokens) " \
                    "VALUES (%s, %s, %s, %s, %s, %s)"

    response = mysql_helper.sql_operation(sql_statement, values)
    if not response:
        return 1
    print("Insertion into myUserExpedition successful")

    # Need to disable user expedition status by updating the table to 'N'
    sql_statement = "UPDATE myuser SET isAvailable = %s WHERE id = %s"
    values = ['N', userID]
    response = mysql_helper.sql_operation(sql_statement, values)
    if not response:
        return 1
    print("User availability updated to 'N'")
    return 0
def redeem_reward(user_obj, reward_obj):
    # CHECK IF THERE IS SUFFICIENT H-TOKEN
    if int(user_obj.HTokens) < int(reward_obj.RewardHToken):
        print("ERROR: Insufficient H-Tokens")
        return 10

    # IF REWARD DOES NOT EXIST
    reward = get_reward_by_id(reward_obj.RewardId)

    # ADDING REWARD INTO USER'S INVENTORY
    sql_statement = "INSERT INTO myrewardinventory (userId, rewardId, rewardExpiry, isRedeemed) " \
                    "VALUES (%s, %s, %s, %s)"
    expiry_date = get_expiry_date(int(reward.RewardDuration))
    data_values = [user_obj.Id, reward_obj.RewardId, expiry_date, 'N']
    sql_response = mysql_helper.sql_operation(sql_statement, data_values)
    if not sql_response:
        print(sql_response)
        return False

    # UPDATE THE USER HTOKEN BALANCE
    remaining_HTokens = user_obj.HTokens - int(reward_obj.RewardHToken)
    sql_statement = "UPDATE myuser SET hTokens = %s WHERE id = %s"
    data_values = [remaining_HTokens, user_obj.Id]
    sql_response = mysql_helper.sql_operation(sql_statement, data_values)
    if not sql_response:
        print(sql_response)
        return 1

    print("SUCCESS: Obtained rewards successfully.")
    return 0
def updateProfile(user_dict, userId):
    # Remove the keys in the dictionary that do not have a value.
    new_dict = {}
    for details in user_dict:
        if user_dict[details] is not None:
            new_dict[details] = user_dict[details]

    if len(new_dict) is 0:
        print("WARNING: No details to be updated. Exiting method now.")
        return True

    # Construct the SQL Statement
    sql_statement_first_half = "UPDATE myuser SET "
    sql_statement_next_half = " WHERE id = %s;"
    data_values = []

    counter = 1
    for details in new_dict:
        if len(new_dict) == counter:
            sql_statement_first_half += details + " = %s"
        else:
            sql_statement_first_half += details + " = %s, "
        data_values.append(new_dict[details])
        counter += 1

    # Update user profile into MYSql Database.
    data_values.append(str(userId))
    sql_statement = sql_statement_first_half + sql_statement_next_half
    mysql_helper.sql_operation(sql_statement, data_values)
    print("SUCCESS: User information updated successfully")
    return True
Beispiel #4
0
def complete_expedition(userID):
    sql_statement = "UPDATE myuser set isAvailable = %s WHERE id = %s"
    response = mysql_helper.sql_operation(sql_statement, ['Y', str(userID)])
    if not response:
        print("First Statement has errors")
        return 1
    sql_statement = "UPDATE myuserexpedition set isOngoing = %s WHERE userId = %s and isOngoing = %s"
    print(sql_statement)
    response = mysql_helper.sql_operation(sql_statement,
                                          ['N', str(userID), 'P'])
    if not response:
        print("Second statement has error")
        return 1
    return 0
Beispiel #5
0
def delete_bookmarks(userID, bookmark_name):
    sql_statement = "DELETE FROM mybookmark WHERE userID = %s AND bookmark_name = %s"
    response = mysql_helper.sql_operation(sql_statement, [userID, bookmark_name])
    if not response:
        return 1
    else:
        return 0
def updateHeroPower(userID, powerLevel):
    sql_statement = "UPDATE myuser set powerLevel = %s WHERE id = %s ;"
    response = mysql_helper.sql_operation(
        sql_statement, [str(powerLevel), str(userID)])
    if not response:
        return 1
    return 0
Beispiel #7
0
def add_ratings(starting_address, ending_address, rating):
    sql_statement = "INSERT INTO myratings (starting_address, ending_address, rating) VALUES(%s, %s, %s)"
    response = mysql_helper.sql_operation(
        sql_statement, [starting_address, ending_address,
                        str(rating)])
    if not response:
        return 1
    return 0
def equip_equipment(userID, equipmentID):
    sql_statement = "UPDATE myheroinventory SET isEquipped = 'Y' WHERE userId = %s AND equipmentId = %s"
    print(userID, equipmentID)
    print(sql_statement)
    if not mysql_helper.sql_operation(sql_statement, [str(userID), str(equipmentID)]):
        return 1
    else:
        return 0
def update_endtime(userID, voucherID):
    sql_statement = "UPDATE myrewardinventory SET endTime = ADDTIME(current_timestamp, \"00:05:00\") WHERE userID = %s AND voucherID = %s;"
    print(userID, voucherID)
    print(sql_statement)
    if not mysql_helper.sql_operation(
            sql_statement, [str(userID), str(voucherID)]):
        return 1
    else:
        return 0
Beispiel #10
0
def add_bookmarks(userID, starting_address, ending_address, bookmark_name):
    sql_statement = "INSERT INTO mybookmark(userID, bookmark_name, starting_address, ending_address) " \
                    "VALUES(%s, %s, %s, %s)"

    response = mysql_helper.sql_operation(sql_statement, [userID, bookmark_name, starting_address, ending_address])
    if not response:
        return 1
    else:
        return 0
def updateHToken(HToken, UserID, method):
    sql_statement = "SELECT hTokens FROM myuser WHERE id = '" + str(
        UserID) + "';"
    response = mysql_helper.select_statement(sql_statement)
    if not response:
        return 1
    current_HToken = int(response[0][0])

    # Add
    if method is 1:
        current_HToken += int(HToken)
    # Subtract
    if method is 0:
        current_HToken -= HToken

    # Update back into the database
    sql_statement = "UPDATE myuser set hTokens = %s WHERE id = %s;"
    mysql_helper.sql_operation(
        sql_statement, [str(current_HToken), str(UserID)])
    if not response:
        return 1
    return 0
def generateOTP(mobile_number):
    OTP = generateOTPCode()
    """ Check if details exists"""
    sql_statement = "SELECT * FROM myotp WHERE phone_number = '" + mobile_number + "';"
    if mysql_helper.check_if_record_exist(sql_statement):
        sql_statement = "UPDATE myotp SET OTP = %s WHERE phone_number = %s"
        data = (OTP, mobile_number)
        if not mysql_helper.sql_operation(sql_statement, data):
            return 1
        print("Record Exists! Update instead!")

    else:
        sql_statement = "INSERT INTO myotp (phone_number, OTP) VALUES(%s, %s)"
        phone_data = (mobile_number, OTP)
        if not mysql_helper.sql_operation(sql_statement, phone_data):
            return 1
        print("Record Doesn't exist, Insert Record")

    if send_message(OTP, mobile_number):
        return 0
    else:
        return 2
def reached_milestone(userId):
    # Get the user's current milestone
    milestone_number = get_milestone_number(userId)
    if milestone_number > 3:
        print("WARNING: User has already reached 3 milestones for the day.")
        return [6]

    # Increment and add the user milestone
    sql_statement = "UPDATE myuser SET milestone = %s WHERE id = '" + str(
        userId) + "';"
    data_values = [str(milestone_number + 1)]
    mysql_helper.sql_operation(sql_statement, data_values)

    # Generate a random equipment.
    rarity = hero_manager.randomize_equipment_id()
    equipment_obj = hero_manager.randomize_equipment_by_rarity(rarity)
    if not equipment_obj:
        print("ERROR: No Equipment Returned")
        return [7]

    # Add the equipment into the user inventory
    hero_manager.obtain_equipment(userId, equipment_obj.Id)
    equipment_obj.print_details()
    return [0, equipment_obj]
def add_user(password, username, email_address, age, contact_number):
    sql_statement = "INSERT INTO myuser(username, contactNumber, emailAddress, age, password) " \
                    "VALUES(%s, %s, %s, %s, %s)"
    if mysql_helper.sql_operation(
            sql_statement,
        (username, contact_number, email_address, age, password)):
        sql_statement = "SELECT id FROM myuser WHERE username = '******';"
        sql_response = mysql_helper.select_statement(sql_statement)
        if not sql_response:  # If it doesnt work
            return 1
        else:
            print(sql_response[0][0])
            return 0, sql_response[0][0]
    else:
        return 1
def obtain_equipment(User_id, Equipment_id):
    sql_statement = "SELECT * FROM myheroinventory WHERE userId = '" + str(User_id) + "' AND equipmentId = '" + str(Equipment_id) + "';"

    # If equipment already exist. Exit the method
    if mysql_helper.check_if_record_exist(sql_statement):
        print("Item already exist")
        return "Success"

    # Save the equipment into the database
    sql_statement = "INSERT INTO myheroinventory (userId, equipmentId, isEquipped) VALUES (%s, %s, %s)"
    data_value = [User_id, Equipment_id, 'N']
    response = mysql_helper.sql_operation(sql_statement, data_value)
    if not response:
        print(response)
        return response
    print("Equipment Obtained Sucesssfully")
    return "Success"
def update_rewards(userID):
    sql_statement = "DELETE FROM myrewardinventory WHERE userId=%s and endTime < current_timestamp;"
    if not mysql_helper.sql_operation(sql_statement, [str(userID)]):
        return 1
    else:
        return 0