From 0f5eddeb59ac9b2fd8b431fe70d6fae3d23c6cc2 Mon Sep 17 00:00:00 2001 From: Francesco Luzzana Date: Wed, 8 Jun 2022 18:01:09 +0200 Subject: [PATCH] mako table --- pad-bis.py | 13 ++++++++++--- templates/index.html | 25 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pad-bis.py b/pad-bis.py index d58ce7b..a1cb81d 100644 --- a/pad-bis.py +++ b/pad-bis.py @@ -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 diff --git a/templates/index.html b/templates/index.html index 14f10a2..241576f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,7 +4,7 @@ - + Padliography II @@ -23,6 +23,27 @@ - {% if pads %} {{pads|safe}} {%endif%} + % if pads: + + + + + + + + + + % for pad in pads: + + + + + + + % endfor +
DateTitleCategoriesOverview
${pad['date']} + ${pad['title']} + ${pad['category']}${pad['overview']}
+ % endif