Compare commits

...

16 Commits

Author SHA1 Message Date
Michal Kunc db87fdcca5 Fix wrong call 2021-11-24 14:37:04 +01:00
Michal Kunc e5c7d0c852 Fix wrong call 2021-11-24 14:31:05 +01:00
Michal Kunc d0e9d6913d Add mongo transaction 2021-11-24 14:25:43 +01:00
Michal Kunc c03ebbf853 Add named capture groups 2021-11-24 12:55:45 +01:00
Michal Kunc 24a9683608 Filter out empty traits 2021-11-19 12:49:26 +01:00
Michal Kunc c7d484fa9a Action style changes 2021-11-19 12:47:30 +01:00
Michal Kunc 74655cc762 Add trait CSS 2021-11-19 12:13:24 +01:00
Michal Kunc 1bae00ea47 add trailing newline 2021-11-19 12:13:05 +01:00
Michal Kunc 182d0c0c86 Add trait list to action 2021-11-19 11:52:42 +01:00
Michal Kunc b459f5f4b1 Optimize docker builds 2021-11-19 11:52:09 +01:00
Michal Kunc 6c1b479bd5 Fix HTML typo 2021-11-19 11:39:35 +01:00
Michal Kunc 91e17be830 Fix type: wrong regex char 2021-11-18 23:52:05 +01:00
Michal Kunc ec6a94f18e Move localization parsing earlier than macro and compendium 2021-11-18 23:39:05 +01:00
Michal Kunc 3982850dd3 Add support for long roll command 2021-11-18 23:36:34 +01:00
Michal Kunc 9641173758 Add todo 2021-11-18 23:32:01 +01:00
Michal Kunc 41a32accfd Add support for localization lookup 2021-11-18 17:59:38 +01:00
8 changed files with 4634 additions and 14 deletions
+3 -1
View File
@@ -1,2 +1,4 @@
.git/
db-importer/
db-importer/
# poetry
poetry.lock
+9 -5
View File
@@ -28,11 +28,15 @@ def main():
if obj_type not in collections:
collections[obj_type] = []
collections[obj_type].append(obj)
print("Inserting all data")
mongo[DB][COLLECTION].insert_many(items)
for collection in collections:
print(f"Inserting collection: {collection}")
mongo[DB][collection].insert_many(collections[collection])
# print("Inserting all data")
# mongo[DB][COLLECTION].insert_many(items)
with mongo.start_session() as s:
s.start_transaction()
mongo.drop_database(DB)
for collection in collections:
print(f"Inserting collection: {collection}")
mongo[DB][collection].insert_many(collections[collection])
s.commit_transaction()
if __name__ == "__main__":
main()
+3 -1
View File
@@ -5,10 +5,12 @@ RUN python3 -m pip install poetry
EXPOSE 5000
WORKDIR /app
COPY db_explorer/ /app/
COPY db_explorer/pyproject.toml /app/
RUN poetry update
RUN poetry run pip install setuptools
COPY db_explorer/ /app/
ENTRYPOINT [ "poetry", "run" ]
CMD [ "gunicorn", "-b=0.0.0.0:5000", "db_explorer:app" ]
+28 -4
View File
@@ -1,4 +1,5 @@
import json
import urllib.parse
import os
import re
@@ -10,16 +11,32 @@ app = Flask(__name__)
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
mongo = PyMongo(app)
LOCALIZATION_JSON = {}
with open("./db_explorer/en.json") as f:
LOCALIZATION_JSON = json.load(f)
@app.template_filter('filter_vtt')
def filter_vtt(text):
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
compendium_re = re.compile(r"@Compendium\[(?P<ref>[^\]]+)\]\{(?P<value>[^\}]+)\}")
def compendium_return(m):
return f"<a>{m.group(2)}</a>"
macro_re = re.compile(r"\[\[\/\S?r\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
# TODO: Actually add links
return f"<a>{m.group('value')}</a>"
macro_re = re.compile(r"\[\[\/\S*?r(?:oll)?\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
def macro_return(m):
if m.group('alt') is not None:
return m.group('alt')
return m.group('sdice')
localize_re = re.compile(r"@Localize\[([^\]]+)\]")
def localize_return(m):
path = m.group(1)
output = LOCALIZATION_JSON
for chunk in path.split('.'):
output = output.get(chunk, {})
if type(output) != str:
output = f"[LOCALIZATION LOOKUP ERROR - {m.group(0)}]"
return output
# Template
text = localize_re.sub(localize_return, text) # Has to be run before Compendium and Macro replacement
text = compendium_re.sub(compendium_return, text)
text = macro_re.sub(macro_return, text)
return text
@@ -37,6 +54,7 @@ def list_actions():
@app.route("/action/<name>")
def show_action(name):
item = mongo.db.action.find_one_or_404({"name": name})
# Actions
if item["data"]["actions"]["value"] == None:
if item["data"]["actionType"]["value"] == 'passive':
item['_action_icon'] = None
@@ -50,7 +68,13 @@ def show_action(name):
item['_action_icon'] = item["data"]["actions"]["value"]
else:
raise ValueError(f'Unknown action: {item["data"]["actionType"]["value"]} - {item["data"]["actions"]["value"]}')
# Traits
_traits = item.get("data", {}).get("traits", {})
item["_all_traits"] = []
item["_all_traits"].append(_traits.get("rarity", {}).get("value", "unkown rarity"))
item["_all_traits"] += _traits.get("value", [])
item["_all_traits"] += _traits.get("custom").split(',')
item["_all_traits"] = list(filter(lambda x: x != '', item["_all_traits"]))
return render_template("action.html", action=item)
if __name__ == "__main__":
File diff suppressed because it is too large Load Diff
+21 -1
View File
@@ -1,3 +1,6 @@
body {
background: #efece9;
}
.action-icon {
height: 26px;
@@ -7,4 +10,21 @@
.sourcebook {
text-align: right;
font-size: 0.8em;
}
}
ul.traits {
padding-left: 0em;
}
li.trait {
display: inline;
font-size: 0.9em;
font-variant: small-caps;
color: #fefefe;
background-color: #5e0000;
border-color: #d8ce83;
border-style: solid;
border-width: 2px;
padding: 0.1em 0.25em;
margin: 0 0;
}
+1 -1
View File
@@ -5,7 +5,7 @@
{% block head %}
<title>{% block title %}PF2 DB{% endblock %}</title>
{% endblock %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}"
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}">
</head>
<body>
{% block body %}
@@ -2,6 +2,11 @@
{% block title %}{{action.name}} - PF2 DB{% endblock %}
{% block body %}
<h1>{{action["name"]}}{{c.actions[action["_action_icon"]]|safe}}</h1>
<p>{{action["data"]["description"]["value"]|filter_vtt|safe}}</p>
<ul class="traits">
{%- for trait in action["_all_traits"] -%}
<li class="trait">{{trait|capitalize}}</li>
{%- endfor -%}
</ul>
{{action["data"]["description"]["value"]|filter_vtt|safe}}
<p class="sourcebook">{{action["data"]["source"]["value"]}}</p>
{% endblock %}