Browse Source

Add spell parsing

marches
Josh Gordon 4 years ago
parent
commit
15eff41eca
  1. 2
      .gitignore
  2. 2
      Spells/saffords_extra_eye
  3. 1
      app/.gitignore
  4. 33
      app/items.py
  5. 3
      app/routes.py
  6. 39
      app/templates/spells.html

2
.gitignore

@ -1,2 +1,2 @@
Stoneshot
Abilities

2
Spells/saffords_extra_eye

@ -1,7 +1,7 @@
Safford's Extra Eye
-------------------
Transmutation Lvl 2
Kind: Transmutation 2
Time: 1 action (Ritual)
Range: Self
Components: S,M (A glass marble, which the spell consumes)

1
app/.gitignore

@ -1 +1,2 @@
__pycache__

33
app/items.py

@ -1,5 +1,24 @@
import glob
def spell_parse(spell_text):
"""Takes in the 'tail' part of a spell file"""
print(spell_text)
lines = spell_text.split("\n")
while len(lines[0].strip()) == 0:
lines = lines[1:]
kind = lines[0]
time = lines[1]
rang = lines[2]
comp = lines[3]
dura = lines[4]
return kind,time,rang,comp,dura,'\n'.join(lines[5:])
def test_spell_parse():
f = open("../Spells/deceptive_sending.txt",'r')
text = '\n'.join(f.read().split("\n")[2:])
print(spell_parse(text))
def get_items(items_dir):
items_list = []
for fname in glob.glob(items_dir):
@ -13,3 +32,17 @@ def get_items(items_dir):
items_list.append((header,tail))
items_list.sort(key=lambda pair: pair[0])
return items_list
def get_spells():
items_list = []
for fname in glob.glob("../Spells/*"):
f = open(fname,'r')
lines = f.read().split('\n')
header = lines[0]
kind,time,rang,comp,dura,tail = spell_parse('\n'.join(lines[2:]))
items_list.append((header,(kind,time,rang,comp,dura),tail))
items_list.sort(key = lambda data: data[0])
return items_list

3
app/routes.py

@ -3,6 +3,7 @@ from flask import render_template
from flask import request
from items import get_items
from items import get_spells
app = Flask(__name__)
@ -28,7 +29,7 @@ def characters():
@app.route('/spells')
def spells():
return render_template('items.html',title="spells",items=get_items("../Spells/*"))
return render_template('spells.html',title="spells",spells=get_spells())
if __name__ == "__main__":
app.run()

39
app/templates/spells.html

@ -0,0 +1,39 @@
<html>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono|IBM+Plex+Sans|IBM+Plex+Sans+Condensed" rel="stylesheet">
<title>{{ title }} - COSI D&D Archive</title>
</head>
<body class="content">
<h1><a href="/">COSI D&D Archive</a></h1>
<table>
<tr style="border: 1px solid; width:80%;">
<ul>
{% for (name,_,_) in spells %}
<li style="display: inline-block;"><a href="#{{name}}"> {{name}} </a> &middot; </li>
{% endfor %}
</ul>
</tr>
</table>
<table>
{% for (name,(kind,time,rang,comp,dura),text) in spells %}
<tr>
<th class="topalign" id="{{name}}">
{{name}}
<hr>
<table>
<tr> {{kind}} <br></tr>
<tr> {{time}} <br></tr>
<tr> {{rang}} <br></tr>
<tr> {{comp}} <br></tr>
<tr> {{dura}} <br></tr>
</table>
</th>
<td class="freeform monospace"> {{text}} </td>
</tr>
{% endfor %}
</table>
<a class="topLink" href="#">Scroll to Top</a>
</body>
</html>
Loading…
Cancel
Save