Browse Source

Add API

master
Josh Gordon 3 years ago
parent
commit
ee84690e6a
  1. 16
      app/routes.py

16
app/routes.py

@ -1,6 +1,6 @@
import sys
from flask import Flask, render_template, request, redirect
from flask import Flask, render_template, request, redirect, jsonify
from items import get_items, get_worlds, get_monsters, get_new_items
@ -229,6 +229,20 @@ def interproll():
price = lower*(1-0.01*roll) + upper*(0.01*roll)
return render_template('interp.html',price=price,roll=roll)
@app.route("/api/<bucket>/<name>")
def item_lookup(bucket,name):
#bucket in ["Items","Spells",...] you get the idea
items = get_items("../{}/*".format(bucket))
for item in items:
if item[0] == name:
return jsonify(title=item[0],headers=item[1],body=item[2])
return "{}"
@app.route("/api/<bucket>/random")
def random_lookup(bucket):
items = get_items("../{}/*".format(bucket))
item = choice(items)
return jsonify(title=item[0],headers=item[1],body=item[2])
if __name__ == "__main__":

Loading…
Cancel
Save