-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
35 lines (25 loc) · 942 Bytes
/
service.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
# service.py this serves as the service layer that contains the request response
from flask import Flask, request, jsonify, render_template
from werkzeug.exceptions import HTTPException
from app import itemkeys
#api = Api(
# app=app,
# version=1.0,
# title="New Itemkeys",
# description="Generate n new itemkeys of 3 characters starting form the last \
# one as input. Max: 3474, keys are distributed 1-999, A01-Z99 sequentially ")
app = Flask(__name__)
@app.route("/newitemkeys/<n>")
def newkeys(n, lastkey=None):
lastkey = request.args.get('lastkey', None)
return jsonify(itemkeys(n,lastkey)), 200
assert(5,100)
@app.errorhandler(Exception)
def handle_exception(e):
# pass through HTTP errors
if isinstance(e, HTTPException):
return e
# handling non-HTTP exceptions only
return render_template("500_generic.html", e=e), 500
if __name__== ("__main__"):
print(newkeys(5,100))