Files
Nuliga2/.ipynb_checkpoints/NuLiga_working-checkpoint.ipynb
T
2026-07-31 13:57:29 +02:00

22 KiB

In [1]:
# Imports 
import os
import sys
import subprocess
import time
import dateutil.parser
from ids import *
#from hallen import *
import locale
import re
import requests
from bs4 import BeautifulSoup
import tabulate
#NummerDJugend=10
#%run ./QR_parser.ipynb
In [2]:
tex_code = r"""
\documentclass[12pt,a4paper,landscape]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[default]{opensans}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage[margin=0.01in]{geometry}
\usepackage{array}
\usepackage{arev}
%\usepackage[T1]{fontenc}
\usepackage{scalefnt}
\usepackage{caption}
\usepackage{array}
\usepackage{graphicx}
\usepackage[absolute]{textpos}
\usepackage{threeparttable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\makeatletter
\newcommand{\thickhline}{%
    \noalign {\ifnum 0=`}\fi \hrule height 2pt
    \futurelet \reserved@a \@xhline
}
\setlength{\tabcolsep}{.16667em}
\newcolumntype{"}{@{\hskip\tabcolsep\vrule width 2pt\hskip\tabcolsep}}
\makeatother
\usepackage{color, colortbl}
\definecolor{LRed}{rgb}{1,.8,.8}
\definecolor{LGreen}{rgb}{.8,1,.8}
\definecolor{LBlue}{rgb}{8,39,142}
\renewcommand{\rmdefault}{ptm}
\setlength{\topmargin}{-2.5cm}
\begin{document}"""
In [3]:
for y in range(len(team)):
#for y in range(10):
    #print('Y=',y)
    #print(team[y])
    #print(y)
    #print(team)
    try: 
        table=tabelle(team[y])
    except: 
        print('Table ', team[y][1], ' failed')
    try:
        Teamspielplan=teamspielplan(team[y])
    except:
        print('Teamspielplan ', team[y][1], 'failed')
    parse=re.compile(r"([K|L]\w*\s\d?)")
    Liga=getliga(team[y])
    #print(y, team[y])
    tex_code += r"""
    \begin{textblock}{3}(0,13.2)
    \begin{figure}
    \includegraphics[width=3cm]{"""+team[y][Shortname]
    tex_code += r"""}\\\centering
    Link zur liga\end{figure}\end{textblock}
    \begin{center}
    \vspace{0cm}
    {\scalefont{3}"""
    tex_code +=r"{}".format(team[y][Alias])
    tex_code +=r"""}\\\scalefont{2}"""
    if y<14:
        tex_code +=r"{}".format(Liga)
        tex_code +=r"""\\"""
    tex_code +=r"""
    \vspace{0cm}
    \end{center}
    \rowcolors{2}{gray!25}{white}
    \begin{table}[h]"""
    tex_code +=r"""\small
   """
    tex_code +=r"""\centering"""
    if len(table[0]) == 9:
        tex_code +=r"""\begin{tabular}{|L{0.6cm}|L{4.3cm}|C{1.2cm}|C{0.5cm}|C{0.4cm}|C{0.5cm}|C{1.5cm}|C{1.2cm}|C{1.3cm}|}"""
        tex_code +=r"""\hline
        \rowcolor{gray!50}"""
        tex_code +=r"""Nr. & Mannschaft &Spiele& S & U &N & Tore & diff. & Punkte\\"""
    if len(table[0]) == 7:
        tex_code +=r"""\begin{tabular}{|L{0.6cm}|L{5.5cm}|C{1.3cm}|C{0.5cm}|C{0.4cm}|C{0.5cm}|C{1.5cm}|}"""
        tex_code +=r"""\hline
        \rowcolor{gray!50}"""
        tex_code +=r"""Nr. & Mannschaft &Spiele& S & U &N & Punkte\\"""
    if len(table[0]) == 3:
        tex_code +=r"""\begin{tabular}{|L{5.5cm}|}"""
        tex_code +=r"""\hline
        \rowcolor{gray!50}"""
        tex_code +=r"""Mannschaft\\"""
    tex_code +=r"""\hline """
    for x in range(len(table)):
        verein = Teamspielplan_kuerzen(table[x][1])
        rank = table[x][0]

        if len(table[x]) > 3:
            if len(table[x][3]) < 3:
                spiele =table[x][2]
            else:
                spiele = '-'
            try: 
                if len(table[x][3]) < 3:
                    siege = table[x][3]
                else: 
                    siege = '-'
            except:
                siege = '0'
        if table[x][3].startswith('zur') or table[x][2].startswith('zur'):
            break
        if len(table[0]) > 3:
            try: 
                unentschieden = table[x][4]
                niederlagen = table[x][5]
            except:
                unentschieden ='-'
                niederlagen = '-'
        if len(table[0]) > 7:
            try:
                tore = table[x][6]
                diff = table[x][7]
                punkte = table[x][8]
            except:
                tore = '-'
                diff = '-'
                punkte = '-'
        if len(table[0]) == 7: 
            try:
                punkte = table[x][6]
                tore = '-'
                diff = '-'
            except:
                punkte = '-'
                print('Tabellenlänge falsch: '+team[y][1])
                print(table)
                #spiele="\multicolumn{4}{|c|}{"+table[x][2]+"}"
        rank = '\\textbf{' + rank + '}'
        #if "Eschweiler" in verein:
        if team[y][0] == verein:
            verein='\\textbf{'+verein+'}'
            spiele = '\\textbf{' + spiele + '}'
            siege = '\\textbf{' + siege + '}'
            unentschieden = '\\textbf{' + unentschieden + '}'
            niederlagen = '\\textbf{' + niederlagen + '}'
            tore = '\\textbf{' + tore + '}'
            diff = '\\textbf{' + diff + '}'
            punkte = '\\textbf{' + punkte + '}'
        if len(table[0]) == 9:
            tex_code += r"""{}&{}&{}&{}&{}&{}&{}&{}&{}\\""".format(rank,verein, spiele,siege,unentschieden,niederlagen,tore,diff,punkte)
        if len(table[0]) == 7:
            tex_code += r"""{}&{}&{}&{}&{}&{}&{}\\""".format(rank,verein, spiele,siege,unentschieden,niederlagen,punkte)
        if len(table[0]) == 3:
            tex_code += r"""{}\\""".format(verein)
        tex_code += os.linesep
    tex_code+=r"""
        \hline
        \end{tabular}"""
    tex_code+=r"""\hspace*{0.3cm}"""
    if len(table[0]) > 3:
        tex_code+=r"""
        \begin{tabular}{|C{0.65cm}|C{2cm}|C{1.0cm}|C{4.1cm}|C{4.1cm}|C{1.2cm}|C{1.4cm}|}
        \hline
        \rowcolor{gray!50}
        Tag & Datum & Zeit& Heim & Gast & Erg.& Halle\\
        """
    if len(table[0]) == 3:
        tex_code+=r"""
        \begin{tabular}{|C{0.65cm}|C{2cm}|C{1.0cm}|C{4.1cm}|C{4.1cm}|C{1.4cm}|}
        \hline
        \rowcolor{gray!50}
        Tag & Datum & Zeit& Heim & Gast & Halle\\
        """
        
    for x in range(len(Teamspielplan)):
        tag = Teamspielplan[x][0]
        if tag == 'Termin offen':
            tag = ' '
            Teamspielplan[x][0]='offen'
            Teamspielplan[x].insert(0,'')
        zeit = Teamspielplan[x][2].lstrip()
        #try:
        #    zeit = Teamspielplan[x][2]
        #except: 
        #    zeit = Teamspielplan[x][2].replace('v', '')    
        if zeit == '00:00':
            zeit = ''
        datum = Teamspielplan[x][1]
        heim = Teamspielplan_kuerzen(Teamspielplan[x][5])
        gast = Teamspielplan_kuerzen(Teamspielplan[x][6])
        if team[y][0] == heim:
            heim='\\textbf{'+team[y][0]+'}'
        if team[y][0] == gast:
            gast='\\textbf{'+team[y][0]+'}'
        turnhalle = Teamspielplan[x][3]
        ergebnis = Teamspielplan[x][7]
        #print(ergebnis)
        if "spielfrei" in gast or "spielfrei" in heim:
            continue
        if len(table[0]) > 3:
            tex_code += r"{}&{}&{}&{}&{}&{}&{}\\".format(tag,datum,zeit[0:5],heim,gast,ergebnis,halle(turnhalle))
            tex_code += os.linesep
        if len(table[0]) == 3:
            tex_code += r"{}&{}&{}&{}&{}&{}\\".format(tag,datum,zeit[0:5],heim,gast,halle(turnhalle))
            tex_code += os.linesep
    tex_code+=r"""
    \hline
    \end{tabular}"""
    tex_code+=r"""
    \end{table}"""
    erklaerung =''
    if any('NG' in sublist for sublist in Teamspielplan):
        erklaerung += '\\textbf{NG} = Gastmannschaft nicht angetreten' 
    if any('NH' in sublist for sublist in Teamspielplan):
        if erklaerung != '':
            erklaerung += '; '
        erklaerung += '\\textbf{NH} = Heimmannschaft nicht angetreten' 
    if any('WG' in sublist for sublist in Teamspielplan):
        if erklaerung != '':
            erklaerung += '; '
        erklaerung += '\\textbf{WG} = Wertung für Heimmannschaft' 
    if any('WH' in sublist for sublist in Teamspielplan):
        if erklaerung != '':
            erklaerung += '; '
        erklaerung += '\\textbf{WH} = Wertung für Auswärtsmannschaft' 
    if any('ZH' in sublist for sublist in Teamspielplan):
        if erklaerung != '':
            erklaerung += '; '
        erklaerung += '\\textbf{ZH} = Heimmannschaft zurückgezogen'
    if any('ZG' in sublist for sublist in Teamspielplan):
        if erklaerung != '':
            erklaerung += '; '
        erklaerung += '\\textbf{ZG} = Gastmannschaft zurückgezogen'
    if erklaerung != '':
        tex_code+=r"""\begin{textblock}{9}(7,15.5)"""
        tex_code+=erklaerung
        tex_code+=r"""\end{textblock}"""
    tex_code+=r"""
    \newpage"""

tex_code += r"""
\centering
\scalefont{5}Die nächsten Spiele\\[0.5cm]
\begin{table}[h]
\centering
\begin{tabular}{|p{3cm} R{10cm} p{0.5cm} p{10cm} p{4cm}|}
\rowcolor{gray!50}
"""
minis=False
Spiele=naechsteSpiele(4)
Tage=0
spiele=0
for spiel in Spiele:
    tag = spiel[0]
    if tag == '' :
        spiele=spiele+1
    else: 
        Tage=Tage+1
#print(Tage)
#print(spiele)
if spiele > 18:
    limit=Tage-1
    #print("begrenzt")
else:
    limit = 8
#print(limit)
ctr=0
for spiel in Spiele:
    tag = spiel[0]
    datum = spiel[1]
    uhrzeit = spiel[2]
    if tag != '' :
        ctr=ctr+1
        if ctr>limit:
            break
        tex_code += r"""\rowcolor{darkgray!50}\hline\multicolumn{5}{|l|}{{\scalefont{2.5}\textbf{\textcolor{white}{"""
        tex_code += r"{}".format(tag + '' + datum)
        tex_code += r"}}}}\\"
        tex_code += os.linesep
    halle=spiel[3]
    heim=spiel[6]
    gast=spiel[7]
    if (heim=="spielfrei") or (gast == "spielfrei"):
        continue 
    if (heim=="\\textbf{Minis}") or (gast == "\\textbf{Minis}"):
        if minis == True:
            continue
        if minis == False:
            minis = True
            #TEXT="Mini Turnier"
            tex_code += r'\LARGE {'+uhrzeit[0:5]+r'}&\multicolumn{3}{c}{\LARGE \\textbf{ MINI Turnier}}&\LARGE {'+ halle +r'}'  
            tex_code += r"\\"
            tex_code += os.linesep
    # 18 Lines
    else:
        # print bla.strftime("%d.%m.%Y %H:%M"), heim,' - ', gast, halle, strasse, ort, gespann
        tex_code += r"\LARGE {}&\LARGE {} &\LARGE :& \LARGE {}&\LARGE {}\\".format(uhrzeit[0:5],heim,gast,halle)
        tex_code += os.linesep
tex_code += r"""
\hline
\end{tabular}
\end{table}"""
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
['Pokal']
[]
[]
[]
[]
[]
[]
In [ ]:
In [ ]:
In [4]:
tex_code+=r"""
\end{document}"""
#print(tex_code)
tex_file = "tabelle.tex"
with open(tex_file, "w") as out_file:
    out_file.write(tex_code)
print("done.")
os.system("/usr/local/texlive/2026/bin/universal-darwin/pdflatex tabelle.tex")
os.system("rm -f *.log *.aux")
Out [4]:
done.
This is pdfTeX, Version 3.141592653-2.6-1.40.28 (TeX Live 2025) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./tabelle.tex
LaTeX2e <2025-11-01>
L3 programming layer <2026-01-19>
(/usr/local/texlive/2025/texmf-dist/tex/latex/extsizes/extarticle.cls
Document Class: extarticle 1996/10/08 v1.0 Non Standard LaTeX document class
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/size12.clo)
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/exscale.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/opensans/opensans.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/fontaxes/fontaxes.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/figureversions/figureversions.sty
)) (/usr/local/texlive/2025/texmf-dist/tex/generic/iftex/ifluatex.sty
(/usr/local/texlive/2025/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/local/texlive/2025/texmf-dist/tex/generic/iftex/ifxetex.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2025/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2025/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2025/texmf-dist/tex/generic/xkeyval/keyval.tex)))))
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/inputenc.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics-def/pdftex.def)
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics/mathcolor.ltx))
(/usr/local/texlive/2025/texmf-dist/tex/latex/colortbl/colortbl.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/tools/array.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2025/texmf-dist/tex/generic/iftex/ifvtex.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/arev.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/arevtext.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/opensans/T1opensans-TLF.fd))
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/textcomp.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/arevmath.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/ams-mdbch.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/arevsymbols.tex))
(/usr/local/texlive/2025/texmf-dist/tex/latex/bera/beramono.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/carlisle/scalefnt.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/caption/caption.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/caption/caption3.sty))
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2025/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/local/texlive/2025/texmf-dist/tex/latex/textpos/textpos.sty
Grid set 16 x 16 = 52.81541pt x 37.34424pt
TextBlockOrigin set to 0pt x 0pt
)
(/usr/local/texlive/2025/texmf-dist/tex/latex/threeparttable/threeparttable.sty
) (/usr/local/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)

No file tabelle.aux.
(/usr/local/texlive/2025/texmf-dist/tex/latex/mathdesign/mdacmr.fd)
(/usr/local/texlive/2025/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2025/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/local/texlive/2025/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/ot1zavm.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/omlzavm.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/omszavm.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/mathdesign/mdbch/omxmdbch.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/mathdesign/mdbch/mdamdbch.fd)
(/usr/local/texlive/2025/texmf-dist/tex/latex/arev/uzavm.fd) [1{/usr/local/texl
ive/2025/texmf-var/fonts/map/pdftex/updmap/pdftex.map}{/usr/local/texlive/2025/
texmf-dist/fonts/enc/dvips/opensans/a_jg4h6q.enc} <./H1.png (PNG copy)>]
[2 <./H2.png (PNG copy)>] [3 <./H3.png (PNG copy)>] [4 <./H4.png (PNG copy)>]
[5 <./D1.png (PNG copy)>] [6 <./D2.png (PNG copy)>] [7 <./mB.png (PNG copy)>]
[8 <./mC.png (PNG copy)>] [9 <./mC2.png (PNG copy)>] [10 <./gJD.png (PNG copy)>
] [11 <./gJD2.png (PNG copy)>] [12 <./gJE.png (PNG copy)>] [13 <./gJE2.png (PNG
 copy)>] [14 <./gJE3.png (PNG copy)>]

LaTeX Warning: `h' float specifier changed to `ht'.

[15] [16] (./tabelle.aux) )</usr/local/texlive/2025/texmf-dist/fonts/type1/asce
nder/opensans/OpenSans-Bold.pfb></usr/local/texlive/2025/texmf-dist/fonts/type1
/ascender/opensans/OpenSans-Regular.pfb>
Output written on tabelle.pdf (16 pages, 121587 bytes).
Transcript written on tabelle.log.
0
In [ ]: