Exemplo n.º 1
0
def post_username():
    username = request.forms.get('username')
    if username: username = username.strip()

    if not username:
        if is_XHR():
            return render_json({"error": "need valid username"}, 409)
        else:
            redirect("/")

    if UserProcess.is_still_processing(username):
        if is_XHR():
            return render_json({
                "update": "/get-update/%s" % username,
                "ws_update": "ws://%s/ws/%s" % (HOST, username)
            })
        else:
            redirect("/await/%s" % username)
    UserProcess(username).get_new_recommendations()

    if is_XHR():
        return render_json({
            "update": "/get-update/%s" % username,
            "ws_update": "ws://%s/ws/%s" % (HOST, username)
        })

    redirect("/await/%s" % username)
Exemplo n.º 2
0
def echo(ws, username):
    if not ws: return "please provide websocket"

    q = UserProcess.get_message_queue(username)
    try:
        if not UserProcess.is_still_processing(username):
            return ws.send(
                json.dumps({
                    "done": True,
                    "results": "/results/%s" % username
                }))
        while True:
            msg = q.get()
            if msg.get("type") == "everything" and msg.get("done"):
                return ws.send(
                    json.dumps({
                        "done": True,
                        "results": "/results/%s" % username
                    }))
            else:
                ws.send(json.dumps({"done": False, "message": msg}))
    finally:
        UserProcess.remove_message_queue(username, q)
Exemplo n.º 3
0
def show_results(username):
    if UserProcess.is_still_processing(username):
        redirect("/await/%s" % username)
    results = UserProcess(username).retrieve_results()
    return render("results", username=username, results=results)
Exemplo n.º 4
0
def await_results(username):
    if not UserProcess.is_still_processing(username):
        redirect("/results/%s" % username)
    return render("await", username=username)