mako table

master
km0 2 years ago
parent ce9c3030ca
commit 0f5eddeb59

@ -3,7 +3,8 @@ logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=lo
# Flask application to serve the web pages
from flask import Flask, render_template, request, redirect, url_for
from flask import Flask, request, redirect, url_for
from flask_mako import MakoTemplates, render_template
# Mediawiki client to interact with the Wiki
import mwclient
@ -45,6 +46,7 @@ class PrefixMiddleware(object):
# create flask application
app = Flask(__name__)
MakoTemplates(app)
# Url prefix for the soupboat
@ -87,8 +89,13 @@ def get_pads():
)
html = site.api('parse', prop='text', page=padliography)
pads = BeautifulSoup(html['parse']['text']['*']).find("table", attrs={"class":"padliography"})
table = BeautifulSoup(html['parse']['text']['*']).find("table", attrs={"class":"padliography"})
headers = [header.text.lower().strip() for header in table.find_all('th')]
pads = [
{headers[i]: cell.text for i, cell in enumerate(row.find_all('td'))}
for row in table.find_all('tr')]
pads = [ pad for pad in pads if pad != {}]
return pads

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="{{url_for('static', filename='css/style.css')}}" />
<link rel="stylesheet" href="${url_for('static', filename='css/style.css')}" />
<title>Padliography II</title>
</head>
<body>
@ -23,6 +23,27 @@
<input type="submit" value="Add" />
</form>
{% if pads %} {{pads|safe}} {%endif%}
% if pads:
<table>
<tr class="header">
<th>Date</th>
<th>Title</th>
<th>Categories</th>
<th>Overview</th>
</tr>
% for pad in pads:
<tr class="${ pad['category']}">
<td class="date">${pad['date']}</td>
<td class="title">
<a href="${pad['link']}" target="_blank"> ${pad['title']} </a>
</td>
<td class="categories">${pad['category']}</td>
<td class="overview">${pad['overview']}</td>
</tr>
% endfor
</table>
% endif
</body>
</html>

Loading…
Cancel
Save