Praesentation/scripts/stats.py

75 lines
1.8 KiB
Python
Raw Normal View History

from bs4 import BeautifulSoup
import requests
from jinja2 import Environment, FileSystemLoader, select_autoescape
from datetime import date
import pandas as pd
import os
env = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape())
def get_befragung():
r = requests.get("https://tvstud-stats.fblanke.de/")
soup = BeautifulSoup(r.text, "html.parser")
total = soup.find("table").find("tfoot").find_all("td")[1].text
return total
def generate_bundesweite_ziele_tex():
template = env.get_template("bundesweite_ziele.tex")
data = get_aktueller_stand_data()
return template.render(
boegen=data["Bund"][0],
eintritte="\\textasciitilde{}~200",
botschafter="?",
befragung=get_befragung(),
datum=date.today().isoformat(),
)
def update_bundesweite_ziele_tex():
with open("../slides/bundesweite_ziele.tex", "w") as f:
f.write(generate_bundesweite_ziele_tex())
# Keep newline at the end of file, single newline will be stripped
f.write("\n")
f.write("\n")
def get_aktueller_stand_data():
data_file = "data.csv"
data = pd.read_csv(data_file)
return data
def generate_aktueller_stand_strukturaufbau():
template = env.get_template("aktueller_stand_strukturaufbau.tex")
data = get_aktueller_stand_data()
return template.render(
bonn=data["Bonn"],
bund=data["Bund"],
)
def update_aktueller_stand_strukturaufbau_tex():
with open("../slides/aktueller_stand_strukturaufbau.tex", "w") as f:
f.write(generate_aktueller_stand_strukturaufbau())
# Keep newline at the end of file, single newline will be stripped
f.write("\n")
f.write("\n")
def main():
update_bundesweite_ziele_tex()
update_aktueller_stand_strukturaufbau_tex()
if __name__ == "__main__":
main()