-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdice.py
More file actions
38 lines (33 loc) · 1.18 KB
/
Copy pathdice.py
File metadata and controls
38 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import webapp2
import logging
import json
from google.appengine.api import urlfetch
root = '/dice/'
class DiceHandler(webapp2.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'application/json-rpc'
data = json.loads(self.request.body)
if data['method'] == 'random':
req = {
"jsonrpc": "2.0",
"method": "generateDecimalFractions",
"params": {
'apiKey': 'f6e74d7b-070e-4f85-865d-d859fc0d078b',
'n': data['n'],
'decimalPlaces': 2,
},
"id": 1
}
result = urlfetch.fetch(
url = 'https://api.random.org/json-rpc/1/invoke',
payload = json.dumps(req),
method = urlfetch.POST,
headers = { 'Content-Type': 'application/json-rpc' },
validate_certificate = False
)
self.response.write(result.content)
return
self.response.write('{}')
app = webapp2.WSGIApplication([
(root + 'f', DiceHandler),
], debug = True)