示例#1
0
def handle_commands(command):
    command = command.lower()
    
    if command in ["/new", "/skip"]:
        new_word = get_new_word()
        insert_into_user_words(
            get_user(session[JWT_PAYLOAD]["name"])[0][0], new_word
        )
        new_word = shuffle_word(new_word).upper()
        session["current_word"] = new_word
        return "Your new word is: " + new_word
    elif command == "/start":
        return """You will get a scrambelled word. Enter as many words as possible </br>Enter <b>/new</b> to get a new word.</br>Enter <b>/show</b> display your currernt word.</br>Enter <b>/shuffle</b> to suffle your current word.</br></br>You can enter a word one by one or seperated by comma."""
    elif command == "/shuffle":
        word = (
            session["current_word"]
            if "current_word" in session
            else get_last_user_word(get_user(session[JWT_PAYLOAD]["name"])[0][0])[0][
                "word"
            ]
        )
        word = shuffle_word(word).upper()
        session['current_word'] = word
        return "Your reshuffled word is " + word
    elif command == "/show":
        if "current_word" in session:
            return "Your current word is: " + session["current_word"]
        else:
            return get_last_user_word(get_user(session[JWT_PAYLOAD]["name"])[0][0])[
                0
            ]["word"]
    else:
        return "Wrong Command"
示例#2
0
def user_info():
    user = db.get_user(current_user.id)
    order_history = db.get_user_order_history(user)
    order_id_name_lists = {}
    order_totals = {}
    for order in order_history:
        order_id_name_lists[order] = order_history[order]['order'][
            'order_list']
        order_totals[order] = order_history[order]['order']['total']
    all_order_name_quantity_lists = {}
    for order_date in order_id_name_lists:
        all_order_name_quantity_lists[
            order_date] = db.get_inventory_from_quantity_named_list(
                order_id_name_lists[order_date])
    order_list = {}
    for order in all_order_name_quantity_lists:
        order_list[order] = {}
        for item in all_order_name_quantity_lists[order]:
            quantity_ordered = int(all_order_name_quantity_lists[order][item])
            order_list[order][item.name] = PurchasedItem(
                item.name, quantity_ordered, item.description, item.price,
                item.type)
    return render_template("user_info.html",
                           user=user,
                           order_list=order_list,
                           order_totals=order_totals)
示例#3
0
def get_user_words(email):
   
    data = get_user_data(get_user(email)[0][0])
    final_data = {}
    for user_word in data:
        if user_word["word"] in final_data:
            final_data[user_word["word"]] = (
                final_data[user_word["word"]] + ", " + user_word["input_word"]
            )
        else:
            final_data[user_word["word"]] = user_word["input_word"]
    return final_data
示例#4
0
def handle_input(message):
    
    try:
        response = {}
        if message.startswith("/"):
            
            response['text'] = handle_commands(message) 
            
        else:

            og_word = get_last_user_word(get_user(session[JWT_PAYLOAD]["name"])[0][0])[0][0]
            
            bad_words = []
            for word in split_text(message):
                is_proper = is_possible(og_word, word)
                if is_proper == "valid":
                    insert_into_user_data(
                        get_user(session[JWT_PAYLOAD]["name"])[0][0], og_word, word
                    )
                else:
                    bad_words.append(word + " is " + is_proper)
            
            if bad_words:
                response['text'] = "</br>".join(bad_words)
                
            else:
                response['text'] = "Input word is valid"
        word = (
            session["current_word"]
            if "current_word" in session
            else ''
            
        )
        response['word'] = word
        return response
                
    except Exception as e:
        response['text'] = "Error " + str(e) + "</br>Try /start command to restart"
        return response
示例#5
0
def login():
    if request.method == "GET":
        return render_template("login.html", error="You must login first.")
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        print "Login - User: "******" Pass: "******"index.html")
示例#6
0
def register():
    db.get_total_inventory_list()
    error = None
    if request.method == 'GET':
        return render_template("register.html")
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        password = hash_password(password, current_app.secret_key)
        district = request.form['district']
        if username and password and district:
            user = db.get_user(username)
            if user:
                error = "Username already exists!"
                return render_template("register.html", error=error)
            else:
                success = db.insert_user(username, password, district)
                user = db.get_user(username)
                if success:
                    login_user(user, remember=True)
                return render_template("index.html")
        else:
            error = "Registration Error: Field missing!"
    return render_template("register.html", error=error)
示例#7
0
def load_user(userid):
    return db.get_user(userid)
示例#8
0
def render_bot():
    user = get_user(session[constants.JWT_PAYLOAD]["name"])
    if len(user) == 0:
        insert_into_users(session[constants.JWT_PAYLOAD]["name"])
    return render_template("bot.html"), 200