Skip to content

Instantly share code, notes, and snippets.

@nosoop
Last active February 20, 2021 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosoop/3207d6cd502cdd104b3da3130dcb58ce to your computer and use it in GitHub Desktop.
Save nosoop/3207d6cd502cdd104b3da3130dcb58ce to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import chevron, json
template_string = r'''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TF2 Attribute List</title>
<style>
body {
font-family: Verdana,Arial,sans-serif;
font-size: 0.75em;
background-color: #111;
color: #FFF;
}
td {
padding: 0.25em;
}
a {
color: #1eb;
}
.attribute {
vertical-align: top;
}
.header {
font-weight: bold;
position: sticky;
top: 0;
background-color: #111;
}
.value_type {
overflow: hidden;
}
.footer {
margin-top: 2.5em;
text-align: center;
}
.positive {
color: #28F;
}
.negative {
color: #F00;
}
tr:nth-child(even) {
background: #222;
}
tr:hover {
background: #333;
}
</style>
</head>
<body>
<h1>List of Team Fortress 2 attributes:</h1>
<table class="attribute-list">
<thead>
<tr class="attribute header">
<th class="id">ID</th>
<th class="name">Name</th>
<th class="description">Description</th>
<th class="is_hidden">Hidden</th>
<th class="value_type">Value Type</th>
<th class="class_name">Class</th>
</tr>
<tbody>
{{#result.attributes}}
<tr class="attribute entry">
<td class="id">{{defindex}}</td>
<td class="name {{effect_type}}">{{name}}</td>
<td class="description">{{description_string}}</td>
<td class="is_hidden">{{#hidden}}true{{/hidden}}{{^hidden}}false{{/hidden}}</td>
<td class="value_type">{{description_format}}</td>
<td class="class_name">{{attribute_class}}</td>
</tr>
{{/result.attributes}}
</tbody>
</table>
<div class="footer">
<div>
Generated with <a href="https://github.com/defunkt/pystache">pystache</a> and
<a href="https://gist.github.com/nosoop/3207d6cd502cdd104b3da3130dcb58ce">this script</a>.
</div>
<div>
Table sorting provided by <a href="https://github.com/tristen/tablesort">tablesort</a>.
</div>
</div>
<!--
- table sorting functionality
- the page degrades gracefully without JS, but sorting is pretty nice to have
-->
<script src="https://unpkg.com/tablesort@5.0.2/dist/tablesort.min.js"
integrity="sha384-MAoWp5qWRu0089eW0evm9gRng72sxH0daE2mkSXN8RoQ99hG/x+Wi8GxUbrgbYLp"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/tablesort@5.0.2/dist/sorts/tablesort.number.min.js"
integrity="sha384-YPqBWGhq2JCwnOo6VsMYgE5XvUqQrzskaIGxc7CByfV6o9viRVq8uAhCs/0iPQBw"
crossorigin="anonymous"></script>
<script>
new Tablesort(document.querySelector('.attribute-list'));
</script>
</body>
</html>
'''
# tf_schema_overview.json is the WebAPI call to IEconItems_440/GetSchemaOverview
print(chevron.render(template_string, json.load(open('tf_schema_overview.json', 'rt'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment