60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
import pandas as pd
|
|
from flask import Flask, render_template, request
|
|
|
|
from download_digital import construct_dataframe
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/")
|
|
def tables(
|
|
url: str = "https://beschaeftigtenbefragung.verdi.de/",
|
|
default_tag: str = "bez_data_2",
|
|
):
|
|
tag = request.args.get("tag")
|
|
if tag is None:
|
|
tag = default_tag
|
|
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.groupby("Bundesland", as_index=False)[["Digitale Befragung"]].sum()
|
|
)
|
|
_print_as_html(df)
|
|
|
|
return render_template("base.html", tables="\n".join(output_str))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|