Advertisement
Deerenaros

ez leaderboard

Nov 11th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import flask
  2. import string
  3. import random
  4.  
  5. app = flask.Flask(__name__)
  6.  
  7. storage = {}
  8.  
  9. url = "http://deerenaros.pythonanywhere.com/"
  10.  
  11. def uid():
  12.     for i in xrange(0, 10):
  13.         yield random.choice(string.ascii_lowercase)
  14.  
  15. @app.route("/")
  16. def hello_world():
  17.     urlid = "".join(uid())
  18.     storage[urlid] = {}
  19.     return """  Hi, now u can use <a href={0}>{0}</a> to access your table (in json).<br/>
  20.                You can also {0}/carina/9000 in order to set Carina's score over nine thousand """.format(url + urlid)
  21.  
  22. @app.route("/<uid>")
  23. def get(uid):
  24.     return str(storage)
  25.     return flask.json.jsonify(storage[uid])
  26.  
  27. @app.route("/<uid>/<name>/<score>")
  28. def set(uid, name, score):
  29.     if uid not in storage:
  30.         return "There is no such table"
  31.     storage[uid][name] = score
  32.     return flask.json.jsonify(storage[uid])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement