-
Notifications
You must be signed in to change notification settings - Fork 2
/
webapp.py
40 lines (31 loc) · 888 Bytes
/
webapp.py
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
39
40
import time
from flask import Flask, jsonify, render_template
from waitress import serve
from camrand import hash_to_int, numberToBase
from camrand import RandomImageSource
import pyximport; pyximport.install()
app = Flask(__name__)
source = RandomImageSource()
source.last_call = time.time()
# GET PUT (override, immuteable) POST (new) DELETE
@app.route('/')
def home():
return render_template('index.html')
@app.route('/seedrandom')
def seed_rand():
source.last_call = time.time()
return jsonify(
status = 'OK',
origin = source.last_call,
result = hash_to_int(source.get_seed())
)
@app.route('/truerandom')
def raw_rand():
source.last_call = time.time()
return jsonify(
status = 'OK',
origin = source.last_call,
result = hex(source.get_seed())[2:]
)
# serve
serve(app, host = '0.0.0.0', port = 4848)