import requests
import re
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
#from hallen import *
NameTabelle=0
Alias=1
KürzelLiga=2
Shortname=3
LigaLink=4
TeamLink=5
#team = [[0 for x in range(5)] for y in range(12)]
team = []
team.append(["Eschweiler SG","1. Herren","VL M", "H1", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=HNR+24%2F25&group=366594","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986183&pageState=vorrunde&championship=HNR+24%2F25&group=366594"])
team.append(["Eschweiler SG II","2. Herren","ROL M", "H2", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363831","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1985997&pageState=vorrunde&championship=AD+24%2F25&group=363831"])
team.append(["Eschweiler SG III","3. Herren","RL M", "H3", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363787","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1993218&pageState=vorrunde&championship=AD+24%2F25&group=363787"])
team.append(["Eschweiler SG IV","4. Herren","RK M", "H4", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363509","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1993222&pageState=vorrunde&championship=AD+24%2F25&group=363509"])
team.append(["Eschweiler SG V","5. Herren","RK M", "H5", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363509","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1993227&pageState=vorrunde&championship=AD+24%2F25&group=363509"])
team.append(["Eschweiler SG", "1. Damen","ROL F", "D1", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363624","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1994286&pageState=vorrunde&championship=AD+24%2F25&group=363624"])
team.append(["Eschweiler SG II", "2. Damen","RL F", "D2", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363794","https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1994277&pageState=vorrunde&championship=AD+24%2F25&group=363794"])
#team.append(["Eschweiler SG", "mA-Jugend", "OLNR MJA", "mA", "https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=RLNR+22%2F23&group=304425","https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1822430&pageState=vorrunde&championship=RLNR+22%2F23&group=304425"]
team.append(["Eschweiler SG", "mB-Jugend", "ROL MJB", "mB", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363863", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986089&pageState=vorrunde&championship=AD+24%2F25&group=363863"])
team.append(["Eschweiler SG", "wB-Jugend", "ROL WJB", "wB", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363764", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986206&pageState=vorrunde&championship=AD+24%2F25&group=363764"])
team.append(["Eschweiler SG", "mC-Jugend", "ROL MJC", "mC", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363476", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986097&pageState=vorrunde&championship=AD+24%2F25&group=363476"])
team.append(["Eschweiler SG II", "mC-Jugend II", "RL MJC", "mC2", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363503", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986113&pageState=vorrunde&championship=AD+24%2F25&group=363503"])
#team.append(["Eschweiler SG", "wC-Jugend", "KL WJC", "wC", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+23%2F24&group=332524", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1893633&pageState=vorrunde&championship=AD+23%2F24&group=332524"])
team.append(["Eschweiler SG", "gD-Jugend", "RL gJD", "gJD", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363580", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986142&pageState=vorrunde&championship=AD+24%2F25&group=363580"])
#team.append(["Eschweiler SG II", "mD-Jugend II", "KK 2 MJD", "mD2", "https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+22%2F23&group=288565", "https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1810114&pageState=vorrunde&championship=AD+22%2F23&group=288565"])
team.append(["Eschweiler SG", "wD-Jugend", "ROL WJD", "wD", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363881", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986230&pageState=vorrunde&championship=AD+24%2F25&group=363881"])
team.append(["Eschweiler SG", "gE-Jugend", "ROL gJE", "gJE", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363676", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986166&pageState=vorrunde&championship=AD+24%2F25&group=363676"])
team.append(["Eschweiler SG II", "gE-Jugend II", "RK 1 gJE", "gJE2", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+24%2F25&group=363822", "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1986191&pageState=vorrunde&championship=AD+24%2F25&group=363822"])
#team.append(["Eschweiler SG", "F-Jugend", "KL F", "F", "https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/groupPage?championship=AD+22%2F23&group=288720", "https://hvmittelrhein-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/teamPortrait?teamtable=1810168&pageState=vorrunde&championship=AD+22%2F23&group=288720"])
#hallen = [[0 for x in range(2)] for y in range(71)]
hallen = []
hallen.append(["02001", "AC2"])
hallen.append(["02002", "AC1"])
hallen.append(["02003", "AC1A"])
hallen.append(["02005", "AC3"])
hallen.append(["02006", "AC4"])
hallen.append(["02007", "M2"])
hallen.append(["02012", "W1"])
hallen.append(["02014", "W3"])
hallen.append(["02018", "R"])
hallen.append(["02019", "ST1"])
hallen.append(["02020", "ST2"])
hallen.append(["02022", "E1"])
hallen.append(["02023", "E2"])
hallen.append(["02029", "KSPH"])
hallen.append(["02030", "BIRK"])
hallen.append(["02031", "GÜRZ"])
hallen.append(["02034", "NIE Gesamtschule"])
hallen.append(["02035", "JÜL Schulzentrum"])
hallen.append(["02036", "JÜL/B Berufsschule"])
hallen.append(["02039", "A1 Gesamtschule"])
hallen.append(["02042", "S1 Am Weiher"])
hallen.append(["02044", "ÜP1 Barbarastrasse"])
hallen.append(["02048", "EY Eynatten/B"])
hallen.append(["02050", "AC7 Bergische Gasse"])
hallen.append(["02051", "LIN/B Bendenweg"])
hallen.append(["02061", "E5 Berufsschule"])
hallen.append(["02062", "R1 Rosentalstrasse 38a"])
hallen.append(["2106", "Tann."])
hallen.append(["2110", "Ringstr."])
hallen.append(["2115", "Königswinter"])
hallen.append(["2118", "Neuenhof"])
hallen.append(["2123", "Niederpleis II"])
hallen.append(["2124", "Hennef West"])
hallen.append(["2126", "Gymn."])
hallen.append(["2138", "Marienschule EU"])
hallen.append(["2140", "Eusk."])
hallen.append(["2145", "Heimer."])
hallen.append(["2147", "Hauptschule Kall"])
hallen.append(["2154", "Bertold-Brecht-Gesamtschule"])
hallen.append(["2155", "Oberpl."])
hallen.append(['02013', 'W2 Krottstrasse'])
hallen.append(['1170', 'E6 Bergrath'])
hallen.append(['4112', 'Bergn.'])
hallen.append(['3161', 'BergGl.'])
hallen.append(['4122', 'Vossbr.'])
hallen.append(['2112', 'Beuel'])
hallen.append(['4104', 'GWN'])
hallen.append(['4101', 'Nut.'])
hallen.append(['3117', 'Pulh.'])
hallen.append(['2122', 'Nieder'])
hallen.append(['2131', 'Rund.'])
hallen.append(['02025', 'E4'])
hallen.append(['4120', 'SpH DBG'])
hallen.append(['4106', 'Eugen.'])
hallen.append(['3109', 'Europ.'])
hallen.append(['02024', 'E3'])
hallen.append(["5025", "GHZ2"])
hallen.append(["4231", "Mühlh."])
hallen.append(["3431", "Haan"])
hallen.append(["7011", "Mönch."])
hallen.append(["3152", "Wahn"])
hallen.append(["3137", "Bockl."])
hallen.append(["4112", "Bergn."])
hallen.append(["3142", "Europ."])
hallen.append(["3154", "Rheind."])
hallen.append(["4114", "Marien."])
hallen.append(["2114", "Rheinb."])
hallen.append(["1133", "Lange."])
hallen.append(["6801", "Kerken"])
hallen.append(["6904", "Lank"])
hallen.append(["2142", "HGH BM"])
hallen.append(["03043", "Zülp. I"])
hallen.append(["03039", "Kuch."])
hallen.append(["03044", "Heim."])
hallen.append(["06012", "FBH"])
hallen.append(["06078", "Nipp."])
hallen.append(["07002", "Scharf."])
hallen.append(["08035", "Hilfarth"])
hallen.append(["02049", "LAII"])
hallen.append(["02046", "R1"])
hallen.append(["06051", "Wahn"])
link_nächsteSpiele = "https://hnr-handball.liga.nu/cgi-bin/WebObjects/nuLigaHBDE.woa/wa/clubMeetings?searchType=0&searchTimeRange=5&searchTimeRangeFrom=&searchTimeRangeTo=&selectedTeamId=WONoSelectionString&club=74726&searchMeetings=Suchen"
def halle(nummer):
for x in range(len(hallen)):
if str(nummer)==hallen[x][0]:
answer = re.split(r'\s+',hallen[x][1])[0]
break
else:
answer = nummer
return(answer)
def tabelle(team):
#print(team[Alias] +' '+ team[LigaLink])
data=fetch_table(team[LigaLink], 0)
for x in range(len(data)):
data[x]=data[x][1:10]
return(data)
def getliga(team):
try:
response = requests.get(team[LigaLink])
except:
print(team)
Fi =str(response.content.decode('utf-8', 'ignore'))
Fi_cleaned = re.sub(r'(\s{2,})',' ',str(Fi))
soup = BeautifulSoup(Fi_cleaned, 'html.parser')
abschnitt = soup.find(id="content-col1")
#print("abschnitt")
#print(abschnitt)
parse=re.compile(r"br\/>\s(.*)\s\
")
name=str(parse.findall(str(abschnitt))[0])
#print("Name")
#print(name)
if len(name) > 20:
if re.search(r'((.*)\s)\
',str(name)) is not None:
name=re.search(r'((.*)\s)\
',str(name)).group(1)
name=re.sub(r"m[ABCDEF]-Jugend", '', name)
name=name.replace(' Männer','')
name=name.replace(' Frauen','')
name=re.sub(r"\w\-Jugend", '', name)
name=re.sub(r"Jugend\sB", '', name)
name=re.sub(r"(männliche)|(weibliche)", '', name)
name=re.sub(r"[mw][ABCDEF]\s", '', name)
name=name.replace(' Spielform','')
#print(name)
return(name)
def teamspielplan(team):
data=fetch_table(team[TeamLink],1)
for x in range(len(data)):
data[x]=data[x][0:8]
response = requests.get(team[TeamLink])
Fi =str(response.content.decode('utf-8', 'ignore'))
Fi_cleaned = re.sub(r'(\s{2,})',' ',str(Fi))
soup = BeautifulSoup(Fi_cleaned, 'html.parser')
nummern=[]
#print(Fi_cleaned)
#print(soup)
for link in soup.find_all('a'):
#print(link.contents)
try:
if len(link.contents[0]) == 4:
nummern.append(link.contents[0])
except:
pass
del nummern[0]
#for x in range(len(nummern)):
# data[x][3]=halle(nummern[x])
return(data)
def Teamspielplan_kuerzen(Mannschaft):
#if "Eschweiler" in Mannschaft:
# Mannschaft ='\\textbf{'+Mannschaft+'}'
if "Borussia Brand (o.W.)" in Mannschaft:
Mannschaft="Bor. Brand (o.W.)"
if "VfR Übach-Palenberg (o.W.)" in Mannschaft:
Mannschaft="Übach-Palenberg (oW)"
if "Schwarz-Rot Aachen (o.W.)" in Mannschaft:
Mannschaft="SR Aachen(o.W.)"
if "SSV Nümbrecht Handball II" in Mannschaft:
Mannschaft="SSV Nümbrecht II"
if "HSG Marienheide/Müllenbach" in Mannschaft:
Mannschaft="HSG Marienheide/Mb"
if "HSG Geislar-Oberkassel" in Mannschaft:
Mannschaft="Geislar-Oberkassel"
if "HBD Löwen Oberberg II" in Mannschaft:
Mannschaft="HBD Oberberg II"
if "JSG Hiesfeld/Aldenrade" in Mannschaft:
Mannschaft="JSG Hiesfeld/Alden."
if "VfR Übach-Palenberg (a.K.)" in Mannschaft:
Mannschaft="VfR Übach-Palenberg a.K."
if "VfR Übach-Palenberg Handball e.V." in Mannschaft:
Mannschaft="VfR Übach-Palenberg"
if "ASV Rurtal Hückelhoven" in Mannschaft:
Mannschaft="ASV Rurtal"
return(Mannschaft)
def fetch_table(Link, nummer):
#print(Link)
try:
response = requests.get(Link)
except:
print(Link)
Fi =str(response.content.decode('utf-8', 'ignore'))
Fi_cleaned = re.sub(r'(\s{2,})',' ',str(Fi))
soup = BeautifulSoup(Fi_cleaned, 'html.parser')
data = []
table = soup.find_all('table', attrs={'class':'result-set'})[nummer]
rows = table.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols])
del data[0]
return(data)
def naechsteSpiele(number):
data=fetch_table(link_nächsteSpiele,0)
response = requests.get(link_nächsteSpiele)
Fi =str(response.content.decode('utf-8', 'ignore'))
Fi_cleaned = re.sub(r'(\s{2,})',' ',str(Fi))
soup = BeautifulSoup(Fi_cleaned, 'html.parser')
for x in range(len(data)):
data[x]=data[x][0:8]
CTR = 0
for x in range(len(data)):
if data[x][0] != '':
CTR+=1
if CTR == number:
break
tabelle=data[:x]
links=[]
nummern=[]
#for link in soup.find_all('a'):
# if len(link.contents[0]) == 4:
# nummern.append(link.contents[0])
#del nummern[0]
for x in range(len(tabelle)):
if tabelle[x][3] != '':
tabelle[x][3]=halle(tabelle[x][3])
for x in range(len(tabelle)):
match=list(filter(lambda y:y[KürzelLiga]==tabelle[x][5], team))
if match != []:
#Zwei Mannschaften in einer Liga
if (tabelle[x][5]=="KK 2 M"):
if (tabelle[x][6] =="Eschweiler SG IV"):
tabelle[x][6] = '\\textbf{4.Herren}'
elif (tabelle[x][7] =="Eschweiler SG IV"):
tabelle[x][7] = '\\textbf{4.Herren}'
if (tabelle[x][5]=="KL M"):
if (tabelle[x][6] =="Eschweiler SG II"):
tabelle[x][6] = '\\textbf{2.Herren}'
elif (tabelle[x][7] =="Eschweiler SG II"):
tabelle[x][7] = '\\textbf{2.Herren}'
if tabelle[x][6].startswith('Eschweiler'):
tabelle[x][6]= '\\textbf{' + match[0][Alias] + '}'
elif tabelle[x][7].startswith('Eschweiler'):
tabelle[x][7]= '\\textbf{' + match[0][Alias] + '}'
else:
print(tabelle[x][5])
continue
if (tabelle[x][5]=="FSF"):
if tabelle[x][6].startswith('Eschweiler'):
tabelle[x][6] = '\\textbf{F-Jugend}'
elif tabelle[x][7].startswith('Eschweiler'):
tabelle[x][7] = '\\textbf{F-Jugend}'
if (tabelle[x][5]=="Mi"):
if tabelle[x][6].startswith('Eschweiler'):
tabelle[x][6] = '\\textbf{Minis}'
else:
tabelle[x][7] = '\\textbf{Minis}'
parse=re.compile(r".\-(\w*)\s.*Jgd")
pokal=parse.findall(str(tabelle[x][5]))
print(pokal)
if (len(pokal) != 0 and tabelle[x][6] !="spielfrei" and tabelle[x][7] !="spielfrei"):
#print('POKAL!!!', pokal)
parse=re.compile(r"\sSG\s(I.*)")
#print(tabelle[x][5], tabelle[x][6], tabelle[x][7])
if tabelle[x][6].startswith('Eschweiler'):
#print("erl.: ", str(pokal[0][0]), " ", str(pokal[0][1]))
nummer=parse.findall(str(tabelle[x][6]))
if len(nummer) == 0:
nummer = 'I'
else:
nummer=nummer[0]
#print('Nummer', nummer)
if pokal[0][1] == 'M':
nummer=len(nummer)-1
tabelle[x][6] = "\\textbf{Pokal "+ team[nummer][Alias]+"}"
elif pokal[0][1] == 'F':
tabelle[x][6] = "\\textbf{Pokal Damen}"
else:
tabelle[x][6] = "\\textbf{"+ tabelle[x][5]+"}"
if tabelle[x][7].startswith('Eschweiler'):
nummer=parse.findall(str(tabelle[x][7]))
#print('Nummer', nummer)
if pokal[0][1] == 'M':
nummer=len(nummer)-1
tabelle[x][6] = "\\textbf{Pokal "+ team[nummer][Alias]+"}"
elif pokal[0][1] == 'F':
tabelle[x][7] = "\\textbf{Damen Pokal}"
else:
tabelle[x][7] = "\\textbf{"+ tabelle[x][5]+"}"
tabelle[x][6]=Teamspielplan_kuerzen(tabelle[x][6])
tabelle[x][7]=Teamspielplan_kuerzen(tabelle[x][7])
tabelle = [x for x in tabelle if x[0] != 'Termin offen']
last_date=''
for x in range(len(tabelle)):
if x == 0:
last_date=tabelle[x][1]
else:
if tabelle[x][1] == '':
#print('cont')
continue
else:
if tabelle[x][1] == last_date:
tabelle[x][0] ==''
tabelle[x][1] == ''
else:
last_date = tabelle[x][1]
#print(last_date)
return(tabelle)