3D die roller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2KB

  1. import webapp2
  2. import logging
  3. import json
  4. from google.appengine.api import urlfetch
  5. root = '/dice/'
  6. class DiceHandler(webapp2.RequestHandler):
  7. def post(self):
  8. self.response.headers['Content-Type'] = 'application/json-rpc'
  9. data = json.loads(self.request.body)
  10. if data['method'] == 'random':
  11. req = {
  12. "jsonrpc": "2.0",
  13. "method": "generateDecimalFractions",
  14. "params": {
  15. 'apiKey': 'f6e74d7b-070e-4f85-865d-d859fc0d078b',
  16. 'n': data['n'],
  17. 'decimalPlaces': 2,
  18. },
  19. "id": 1
  20. }
  21. result = urlfetch.fetch(
  22. url = 'https://api.random.org/json-rpc/1/invoke',
  23. payload = json.dumps(req),
  24. method = urlfetch.POST,
  25. headers = { 'Content-Type': 'application/json-rpc' },
  26. validate_certificate = False
  27. )
  28. self.response.write(result.content)
  29. return
  30. self.response.write('{}')
  31. app = webapp2.WSGIApplication([
  32. (root + 'f', DiceHandler),
  33. ], debug = True)