Contact me to be added to this repository. Push the creations you make for D&D, and they will be displayed in a nice website. See the website for how to contribute.
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.
 
 
 
 
 
 

107 lines
3.5 KiB

import sys
from flask import Flask, render_template, request, redirect
from items import get_items
from random import choice, sample
if sys.version_info.major < 3:
# XXX OOF
reload(sys)
sys.setdefaultencoding('utf8')
app = Flask(__name__)
@app.route('/style.css')
def style():
return render_template('style.css')
@app.route('/')
def index():
featureType = choice(["Item","Place","Spell"])
item = choice(get_items("../"+featureType+"s/*"))
return render_template('index.html',featureType=featureType,featureText=item)
"""
@app.route('/add')
def addPage():
return render_template('add.html')
@app.route('/addContent', methods=['POST'])
def addContent():
bucket = request.form['bucket']
text = request.form['entry']
title = text.partition('\n')[0].lower().replace(".","").replace("/","").replace(" ","_").strip()
if bucket in ["Items","Places","Characters","Spells"]:
f = open("../" + bucket + "/" + title + ".txt",'x')
f.write(text)
f.close()
return render_template('add.html')
else:
return "<h1>bruh</h1><p><b>Pls no.</b></p>"
"""
@app.route('/search', methods=['POST'])
def search():
typ = request.form['type']
query = request.form['inputText']
print(typ + ": " + query)
results = []
for direct in ["../Items/*","../Places/*","../Spells/*"]:
objects = get_items(direct)
for (name,heads,body) in objects:
if typ == "name":
if query.lower() in name.lower():
results.append((name,heads,body))
elif typ == "rarity":
if "rarity" in [h[0].lower() for h in heads]:
if query.lower() in [h[1].lower() for h in heads if h[0].lower() == "rarity"]:
results.append((name,heads,body))
elif typ == "aura":
if "aura" in [h[0].lower() for h in heads]:
if query.lower() in [h[1].lower() for h in heads if "aura" in h[0].lower()][0]:
results.append((name,heads,body))
elif typ == "text":
if query.lower() in body.lower():
results.append((name,heads,body))
print("Number of results: " + str(len(results)))
featureType = choice(["Item","Place","Spell"])
item = choice(get_items("../"+featureType+"s/*"))
return render_template('index.html',featureType=featureType,featureText=item, searchResults=results)
def bucket_route(uri, dir, sing=None):
if sing is None:
sing = dir[:-1] # minus "s"
path = '../' + dir + '/*'
root = '/' + uri
def render_bucket():
return render_template('listing.html', title=dir, uri=uri, items=get_items(path))
app.add_url_rule(root, 'render_' + uri, render_bucket)
def random_bucket():
nm = choice(get_items(path))[0]
return redirect(root + '#' + nm)
app.add_url_rule(root + '/random', 'random_' + uri, random_bucket)
def bucket_table(amt):
try:
return render_template('table.html', title=sing + ' Table', items=sample(get_items(path), amt), roll=amt)
except ValueError:
return render_template('table.html', title='you dun goofed', error="Can't construct that table (not enough items?)")
app.add_url_rule(root + '/table/<int:amt>', dir + '_table', bucket_table)
bucket_route('items', 'Items')
bucket_route('places', 'Places')
bucket_route('characters', 'Characters')
bucket_route('spells', 'Spells')
bucket_route('feats', 'Feats')
if __name__ == "__main__":
app.run()