def main(request):
    if request.path == "/api":
        action = request.args["action"]
        
        return werkwrappers.Response(api.handleAction(data, action, request.args))
    
    if request.path == "/":
        path = "/index.html"
    else:
        path = request.path
    
    try:
        with open("../client"+path, "r") as f:
            return werkwrappers.Response(f.read())
    except IOError:
        with open("../client/404.html", "r") as f:
            return werkwrappers.Response(f.read(), status=404)
Пример #2
0
def main(request):
    path = request.path
    
    if path == "/api":
        action = request.args["action"]
        
        return werkwrappers.Response(api.handleAction(data, action, request.args))
    
    if path == "/profile.html":
        userinfo = data.get_user_info(request.args["user"])
        
        if request.args.get("updown", "False") == "True":
            updown = True
        else:
            updown = False
        
        content = """<!DOCTYPE html>
<html style="height:100%;">
    <meta charset="UTF-8">
"""
        
        content += header
        
        content += "<div style=\"text-align:center;\">\n<h1>Name</h1>"
        
        content += """%s %s<br/>%s<br/>""" % (userinfo["first_name"],
                                              userinfo["last_name"],
                                              request.args["user"])
        
        content += """<h1>Score</h1>"""
        
        content += "%d" % (userinfo["score"])
        
        content += """<h1>Achievements</h1></div>"""
        
        content += achievements.generate_achievements_html(userinfo["achievements"],
                                                           updown)
        
        content += "</html>"
        
        return werkwrappers.Response(content, mimetype="text/html")
    elif path == "/scoreboard.html":
        scoreboard = data.get_scoreboard(int(request.args["count"]))
        
        content = """<!DOCTYPE html>
<html style="height:100%s;margin:0px 0px">
    <meta charset="UTF-8">
    <body>
    %s
    <table style="width:100%s">
    <tr>
        <th>User</th>
        <th>Score</th>
    </tr>
""" % ("%", header, "%")
        
        for user in scoreboard:
            score = data.get_user_info(user)["score"]
            
            content += "<tr><th>%s</th><th>%d</th></tr>" % (user, score)
        
        content += " </table>\n</body>\n</html>\n"
        
        return werkwrappers.Response(content, mimetype="text/html")
    elif path in ["/index.html", "/"]:
        return werkwrappers.Response("""<!DOCTYPE html>
<html style="height:100%s">
    <meta charset="UTF-8">
    %s
</html>
""" % ("%", header), mimetype="text/html")
    
    try:
        with open("../client"+path, "r") as f:
            return werkwrappers.Response(f.read().replace("!!insertheader!!", header), mimetype="text/html")
    except IOError:
        with open("../client/404.html", "r") as f:
            return werkwrappers.Response(f.read().replace("!!insertheader!!", header), status=404, mimetype="text/html")
Пример #3
0
def main(request):
    path = request.path

    if path == "/api":
        action = request.args["action"]

        return werkwrappers.Response(
            api.handleAction(data, action, request.args))

    if path == "/profile.html":
        userinfo = data.get_user_info(request.args["user"])

        if request.args.get("updown", "False") == "True":
            updown = True
        else:
            updown = False

        content = """<!DOCTYPE html>
<html style="height:100%;">
    <meta charset="UTF-8">
"""

        content += header

        content += "<div style=\"text-align:center;\">\n<h1>Name</h1>"

        content += """%s %s<br/>%s<br/>""" % (userinfo["first_name"],
                                              userinfo["last_name"],
                                              request.args["user"])

        content += """<h1>Score</h1>"""

        content += "%d" % (userinfo["score"])

        content += """<h1>Achievements</h1></div>"""

        content += achievements.generate_achievements_html(
            userinfo["achievements"], updown)

        content += "</html>"

        return werkwrappers.Response(content, mimetype="text/html")
    elif path == "/scoreboard.html":
        scoreboard = data.get_scoreboard(int(request.args["count"]))

        content = """<!DOCTYPE html>
<html style="height:100%s;margin:0px 0px">
    <meta charset="UTF-8">
    <body>
    %s
    <table style="width:100%s">
    <tr>
        <th>User</th>
        <th>Score</th>
    </tr>
""" % ("%", header, "%")

        for user in scoreboard:
            score = data.get_user_info(user)["score"]

            content += "<tr><th>%s</th><th>%d</th></tr>" % (user, score)

        content += " </table>\n</body>\n</html>\n"

        return werkwrappers.Response(content, mimetype="text/html")
    elif path in ["/index.html", "/"]:
        return werkwrappers.Response("""<!DOCTYPE html>
<html style="height:100%s">
    <meta charset="UTF-8">
    %s
</html>
""" % ("%", header),
                                     mimetype="text/html")

    try:
        with open("client/" + path, "r") as f:
            return werkwrappers.Response(f.read().replace(
                "!!insertheader!!", header),
                                         mimetype="text/html")
    except IOError:
        with open("client/404.html", "r") as f:
            return werkwrappers.Response(f.read().replace(
                "!!insertheader!!", header),
                                         status=404,
                                         mimetype="text/html")