mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-04-15 06:10:33 +03:00
add small doc on /index.html
This commit is contained in:
parent
6a8acdc55a
commit
7762874b8a
77
utils.py
77
utils.py
@ -3,6 +3,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
|
import falcon
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
@ -140,50 +141,14 @@ def _get_bearer() -> str:
|
|||||||
return bearer
|
return bearer
|
||||||
|
|
||||||
|
|
||||||
html_table_generator = """
|
def build_index_page(app: falcon.App, index_path: str) -> None:
|
||||||
// Thanks to https://stackoverflow.com/a/21065846
|
with open(index_path, 'w', encoding='utf-8') as index_file: # kinda documentation on main page
|
||||||
var _table_ = document.createElement('table'),
|
from falcon import inspect
|
||||||
_tr_ = document.createElement('tr'),
|
app_info = inspect.inspect_app(app)
|
||||||
_th_ = document.createElement('th'),
|
app_info_str = app_info.__str__().replace('\n', '<br>')
|
||||||
_td_ = document.createElement('td');
|
|
||||||
|
|
||||||
// Builds the HTML Table out of myList json data from Ivy restful service.
|
index_file.write(index_template.format(body=app_info_str))
|
||||||
function buildHtmlTable(arr) {
|
|
||||||
var table = _table_.cloneNode(false),
|
|
||||||
columns = addAllColumnHeaders(arr, table);
|
|
||||||
for (var i = 0, maxi = arr.length; i < maxi; ++i) {
|
|
||||||
var tr = _tr_.cloneNode(false);
|
|
||||||
for (var j = 0, maxj = columns.length; j < maxj; ++j) {
|
|
||||||
var td = _td_.cloneNode(false);
|
|
||||||
cellValue = arr[i][columns[j]];
|
|
||||||
td.appendChild(document.createTextNode(arr[i][columns[j]] || ''));
|
|
||||||
tr.appendChild(td);
|
|
||||||
}
|
|
||||||
table.appendChild(tr);
|
|
||||||
}
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a header row to the table and returns the set of columns.
|
|
||||||
// Need to do union of keys from all records as some records may not contain
|
|
||||||
// all records
|
|
||||||
function addAllColumnHeaders(arr, table) {
|
|
||||||
var columnSet = [],
|
|
||||||
tr = _tr_.cloneNode(false);
|
|
||||||
for (var i = 0, l = arr.length; i < l; i++) {
|
|
||||||
for (var key in arr[i]) {
|
|
||||||
if (arr[i].hasOwnProperty(key) && columnSet.indexOf(key) === -1) {
|
|
||||||
columnSet.push(key);
|
|
||||||
var th = _th_.cloneNode(false);
|
|
||||||
th.appendChild(document.createTextNode(key));
|
|
||||||
tr.appendChild(th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
table.appendChild(tr);
|
|
||||||
return columnSet;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
activity_table_html_template = """
|
activity_table_html_template = """
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
@ -220,21 +185,13 @@ activity_table_html_template = """
|
|||||||
</body>
|
</body>
|
||||||
</html>"""
|
</html>"""
|
||||||
|
|
||||||
activity_table_html_styles = """
|
index_template = """
|
||||||
table {
|
<!DOCTYPE html>
|
||||||
margin-bottom: 20px;
|
<html>
|
||||||
border: 1px solid #dddddd;
|
<head>
|
||||||
border-collapse: collapse;
|
<meta charset="utf-8">
|
||||||
}
|
</head>
|
||||||
table th {
|
<body>
|
||||||
font-weight: bold;
|
<p>{body}</p>
|
||||||
padding: 5px;
|
</body>
|
||||||
background: #efefef;
|
</html>"""[1:]
|
||||||
border: 1px solid #dddddd;
|
|
||||||
}
|
|
||||||
table td {
|
|
||||||
border: 1px solid #dddddd;
|
|
||||||
padding: 5px;
|
|
||||||
text-align:center;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
12
web.py
12
web.py
@ -1,6 +1,7 @@
|
|||||||
import model
|
import model
|
||||||
import json
|
import json
|
||||||
import falcon
|
import falcon
|
||||||
|
import os
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
@ -86,14 +87,17 @@ app.add_route('/api/diff/{action_id}', ActivityDiff())
|
|||||||
app.add_route('/leaderboard/{leaderboard}/platform/{platform}', ActivityHtml())
|
app.add_route('/leaderboard/{leaderboard}/platform/{platform}', ActivityHtml())
|
||||||
app.add_route('/diff/{action_id}', ActivityDiffHtml())
|
app.add_route('/diff/{action_id}', ActivityDiffHtml())
|
||||||
|
|
||||||
app.add_route('/{var}', MainPage())
|
|
||||||
|
|
||||||
app.add_route('/api/cache/{action}', Cache())
|
app.add_route('/api/cache/{action}', Cache())
|
||||||
|
|
||||||
application = app # for uwsgi
|
application = app # for uwsgi
|
||||||
|
|
||||||
|
index_file = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'), 'index.html')
|
||||||
|
|
||||||
|
utils.build_index_page(app, index_file)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import waitress
|
import waitress
|
||||||
import os
|
|
||||||
app.add_static_route('/js', os.path.join(os.path.dirname(os.path.abspath(__file__)), 'js'))
|
app.add_static_route('/js', os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'), 'js'))
|
||||||
|
app.add_static_route('/', os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'))
|
||||||
waitress.serve(app, host='127.0.0.1', port=9485)
|
waitress.serve(app, host='127.0.0.1', port=9485)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user