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.

76 lines
2.4 KiB

4 years ago
4 years ago
  1. import sys
  2. from flask import Flask, render_template, request
  3. from items import get_items
  4. from random import choice
  5. if sys.version_info.major < 3:
  6. # XXX OOF
  7. reload(sys)
  8. sys.setdefaultencoding('utf8')
  9. app = Flask(__name__)
  10. @app.route('/style.css')
  11. def style():
  12. return render_template('style.css')
  13. @app.route('/')
  14. def index():
  15. featureType = choice(["Item","Place","Spell"])
  16. item = choice(get_items("../"+featureType+"s/*"))
  17. return render_template('index.html',featureType=featureType,featureText=item)
  18. @app.route('/search', methods=['POST'])
  19. def search():
  20. typ = request.form['type']
  21. query = request.form['inputText']
  22. print(typ + ": " + query)
  23. results = []
  24. for direct in ["../Items/*","../Places/*","../Spells/*"]:
  25. objects = get_items(direct)
  26. for (name,heads,body) in objects:
  27. if typ == "name":
  28. if query.lower() in name.lower():
  29. results.append((name,heads,body))
  30. elif typ == "rarity":
  31. if "rarity" in [h[0].lower() for h in heads]:
  32. if query.lower() in [h[1].lower() for h in heads if h[0].lower() == "rarity"]:
  33. results.append((name,heads,body))
  34. elif typ == "aura":
  35. if "aura" in [h[0].lower() for h in heads]:
  36. if query.lower() in [h[1].lower() for h in heads if h[0].lower() == "aura"]:
  37. results.append((name,heads,body))
  38. elif typ == "text":
  39. if query.lower() in body.lower():
  40. results.append((name,heads,body))
  41. print("Number of results: " + str(len(results)))
  42. featureType = choice(["Item","Place","Spell"])
  43. item = choice(get_items("../"+featureType+"s/*"))
  44. return render_template('index.html',featureType=featureType,featureText=item, searchResults=results)
  45. @app.route('/items')
  46. def items():
  47. return render_template('listing.html',title="Items",items=get_items("../Items/*"))
  48. @app.route('/places')
  49. def places():
  50. return render_template('listing.html',title="Places",items=get_items("../Places/*"))
  51. @app.route('/characters')
  52. def characters():
  53. return render_template('listing.html',title="Characters",items=get_items("../Characters/*"))
  54. @app.route('/spells')
  55. def spells():
  56. return render_template('listing.html',title="Spells",items=get_items("../Spells/*"))
  57. if __name__ == "__main__":
  58. app.run()