app.py 535 B

1234567891011121314151617181920
  1. from random import randint
  2. from flask import Flask, request
  3. import logging
  4. app = Flask(__name__)
  5. logging.basicConfig(level=logging.INFO)
  6. logger = logging.getLogger(__name__)
  7. @app.route("/rolldice")
  8. def roll_dice():
  9. player = request.args.get('player', default = None, type = str)
  10. result = str(roll())
  11. if player:
  12. logger.warning("%s is rolling the dice: %s", player, result)
  13. else:
  14. logger.warning("Anonymous player is rolling the dice: %s", result)
  15. return result
  16. def roll():
  17. return randint(1, 6)