2023-08-20 00:54:33 +02:00

53 lines
1.5 KiB
Python

import pandas as pd
from flask import Flask, render_template
from download_digital import construct_dataframe
app = Flask(__name__)
@app.route("/")
def tables(
url: str = "https://beschaeftigtenbefragung.verdi.de/",
tag: str = "bez_data_2",
):
df = construct_dataframe(url=url, tag=tag, grouped=False)
output_str = []
def _print_as_html(df: pd.DataFrame):
df = df.astype({"Digitale Befragung": "Int32"})
with pd.option_context("display.max_rows", None):
table = df.to_html(
index_names=False,
justify="left",
index=False,
classes="sortable dataframe",
)
tfoot = [
" <tfoot>",
" <td>Gesamt</td>",
]
for i in range(len(df.columns) - 2):
tfoot.append(" <td/>")
tfoot.extend(
[
f" <td>{df['Digitale Befragung'].sum()}</td>",
" </tr>",
" </tfoot>",
]
)
tfoot = "\n".join(tfoot)
idx = table.index("</table>")
output_str.append(table[: idx - 1])
output_str.append(tfoot)
output_str.append(table[idx:])
_print_as_html(df)
_print_as_html(
df.groupby("Bundesland", as_index=False)[["Digitale Befragung"]].sum()
)
return render_template("base.html", tables="\n".join(output_str))