Browse Source

Link to Autarch treasure generator

master
Brandon Cornejo 6 months ago
parent
commit
f7c0f7d001
  1. 39
      acks/templates/base.html
  2. 17
      acks/templates/treasure.html
  3. 35
      acks/views.py
  4. 55
      requirements.txt

39
acks/templates/base.html

@ -2,14 +2,15 @@
('/', 'index', 'Home'),
('/handbook', 'handbook', 'Handbook'),
('/worldmap', 'worldmap', 'World Map'),
('', 'generate', 'Generate'),
('.header', 'generate', 'Generate'),
('.header', 'other', 'Other'),
('/npc/spells', 'spells', 'Spells'),
('/api/schema', 'api', 'API'),
] %}
{% set generation_bar = [
('/npc/party', 'npcparty', 'NPC Party'),
('/npc/single', 'npcsingle', 'Single NPC'),
('/treasure', 'treasure', 'Treasure'),
('http://autarch.co/treasure', 'treasure', 'Treasure'),
] %}
{% set active_page = active_page|default('index') %}
@ -47,12 +48,18 @@
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
{% for ghref, gid, glabel in generation_bar %}
<li><a href="{{ ghref | e }}">{{ glabel|e }}</a></li>
<li>
<a href="{{ ghref | e }}" {% if gid == 'treasure' %}target="_blank"{% endif %}>
{{ glabel|e }}
</a>
</li>
{% endfor %}
</ul>
</div>
{% else %}
<a href="{{ href|e }}">{{ label|e }}</a>
{% if href != '.header' %}
<a href="{{ href|e }}">{{ label|e }}</a>
{% endif %}
{% endif %}
</li>
{% endfor %}
@ -63,20 +70,22 @@
<div class="uk-offcanvas-bar uk-flex uk-flex-column">
<ul class="uk-nav uk-nav-primary uk-nav-center uk-margin-auto-vertical">
{% for href, id, label in navigation_bar %}
<li {% if id == active_page %} class="uk-active" {% endif %}>
{% if href == '.header' %}
<li class="uk-nav-header">{{ label|e }}</li>
{% if id == 'generate' %}
<a href="">{{ label |e }}</a>
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
{% for ghref, gid, glabel in generation_bar %}
<li><a href="{{ ghref | e }}">{{ glabel|e }}</a></li>
{% endfor %}
</ul>
</div>
{% else %}
<a href="{{ href|e }}">{{ label|e }}</a>
{% for ghref, gid, glabel in generation_bar %}
<li {% if gid == active_page %} class="uk-active" {% endif %}>
<a href="{{ ghref | e }}" {% if gid == 'treasure' %}target="_blank"{% endif %}>
{{ glabel|e }}
</a>
</li>
{% endfor %}
{% endif %}
{% else %}
<li {% if id == active_page %} class="uk-active" {% endif %}>
<a href="{{ href|e }}">{{ label|e }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>

17
acks/templates/treasure.html

@ -27,6 +27,10 @@
<div class="uk-flex uk-flex-center uk-margin-bottom uk-margin-top">
<h1 class="uk-text-center"><strong>Adventurer Conqueror King</strong>Treasure Generator</h1>
</div>
<div id="frame-container">
<iframe id="treasure-frame" src="http://autarch.co/treasure"/>
</div>
<!--
<div class="uk-flex uk-flex-bottom uk-flex-center uk-margin-large-bottom">
<div>
<label for="treasure-type" class="uk-form-label">Select Treasure Type</label>
@ -48,10 +52,23 @@
</div>
</div>
{% endif %}
-->
{% endblock %}
{% block head %}
<style>
#frame-container {
display: flex;
width: 100%;
height: 85vh;
flex-direction: column:
}
#treasure-frame {
flex-grow: 1;
border: none;
margin: 0;
padding: 0;
}
h1 strong {
display: block;
font-size: 50%;

35
acks/views.py

@ -1,4 +1,5 @@
import requests
from lxml import html
from flask import current_app, Blueprint, render_template, url_for, redirect
@ -6,8 +7,7 @@ default_views = Blueprint('default_views', __name__, url_prefix='/')
@default_views.route('/')
def index():
return redirect(url_for('npc_views.generate_npc_party'))
# return render_template('index.html')
return render_template('index.html')
@default_views.route('/handbook')
def handbook():
@ -20,14 +20,27 @@ def worldmap():
@default_views.route('/treasure')
@default_views.route('/treasure/<string:treasure_type>')
def treasure(treasure_type=None):
# Unused, we can't tap into Autarch's generator, so just link to a new tab
# in navigation bar now
'''
if treasure_type is not None:
headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
payload = {
"treasure_type": treasure_type,
"form_id": "acks_treasure_form",
"form_build_id": "form-PqO-1VglfW4Q3x1fm7HMewhLFjst2oxY5AR_m6WOGBg"
}
response = requests.request("POST", "http://autarch.co/system/ajax", data=payload, headers=headers)
generated_treasure = response.json()[1]["data"].replace('class="form-textarea"', 'class="uk-textarea"')
return render_template('treasure.html', generated_treasure=generated_treasure, treasure_type=treasure_type)
with requests.Session() as s:
import pudb;pu.db
# First grab the page to pull a fresh form_build_id
treasure_page = s.get('http://autarch.co/treasure')
dom_tree = html.fromstring(treasure_page.content)
form_build_id = dom_tree.find('.//input[@name="form_build_id"]').attrib['value']
# Use that form_build_id to make a request for generated treasure
headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
payload = {
"form_id": "acks_treasure_form",
"form_build_id": form_build_id,
"treasure_type": treasure_type
}
response = s.post("http://autarch.co/system/ajax", data=payload, headers=headers)
print("TG Response: {}, Payload: {}".format(response.text, payload))
generated_treasure = response.json()[1]["data"].replace('class="form-textarea"', 'class="uk-textarea"')
return render_template('treasure.html', generated_treasure=generated_treasure, treasure_type=treasure_type)
'''
return render_template('treasure.html')

55
requirements.txt

@ -1,18 +1,37 @@
ansi2html==1.5.2
cryptography==1.7.1
culour==0.1
enum34==1.1.6
idna==2.2
ipaddress==1.0.17
keyring==10.1
keyrings.alt==1.3
pudb==2018.1
pyasn1==0.1.9
pycrypto==2.6.1
Pygments==2.3.1
pygobject==3.22.0
pyxdg==0.25
SecretStorage==2.3.1
six==1.12.0
urwid==2.0.1
virtualenv==16.6.1
alembic==1.3.1
aniso8601==8.0.0
attrs==19.3.0
blinker==1.4
certifi==2019.11.28
chardet==3.0.4
Click==7.0
Flask==1.1.1
Flask-Admin==1.5.4
Flask-Potion==0.16.0
Flask-SQLAlchemy==2.4.1
idna==2.8
importlib-metadata==1.1.0
itsdangerous==1.1.0
Jinja2==2.10.1
jsonschema==3.2.0
lxml==4.6.1
Mako==1.1.0
MarkupSafe==1.1.1
more-itertools==8.0.0
pkg-resources==0.0.0
pudb==2019.2
Pygments==2.5.2
pyrsistent==0.15.6
python-dateutil==2.8.1
python-editor==1.0.4
requests==2.22.0
rfc3987==1.3.8
six==1.13.0
SQLAlchemy==1.3.11
strict-rfc3339==0.7
urllib3==1.25.7
urwid==2.1.0
uWSGI==2.0.18
Werkzeug==0.16.0
WTForms==2.2.1
zipp==0.6.0
Loading…
Cancel
Save