Compare commits
10 Commits
frontend
...
ScraperTes
| Author | SHA1 | Date | |
|---|---|---|---|
| c86a93c153 | |||
| 43eb1d421d | |||
| c2568c86ef | |||
| cf46fdfbb7 | |||
| 791d20139d | |||
| c3a6626d6f | |||
| 5960e44b17 | |||
|
|
13f6e2e3b9 | ||
|
|
9a007f504c | ||
|
|
b5fdbb3230 |
@@ -1,9 +1,11 @@
|
||||
from flask import session
|
||||
from lewy_db import baza as ldb
|
||||
from lewy_globals import colors as c
|
||||
import json
|
||||
import lewy_globals
|
||||
import requests
|
||||
import time
|
||||
from sqlalchemy import func
|
||||
|
||||
def safe_traverse(obj: dict, path: list, default=None):
|
||||
result = obj
|
||||
@@ -12,7 +14,7 @@ def safe_traverse(obj: dict, path: list, default=None):
|
||||
result = result[x]
|
||||
except KeyError:
|
||||
result = default
|
||||
# print(f"error reading: {' -> '.join(path)} - returning: {default}")
|
||||
print(f"safe_traverse: error reading {' -> '.join(path)} - returning: {default}")
|
||||
finally:
|
||||
return result
|
||||
|
||||
@@ -45,6 +47,17 @@ class scraper:
|
||||
else:
|
||||
return False
|
||||
|
||||
def to_iso_compatible_date(self, dmy_date: str):
|
||||
"""
|
||||
Zamienia datę z formatu DD.MM.YY na YYYY-MM-DD
|
||||
|
||||
:param dmy_date: Data w formacie DD.MM.YY
|
||||
:type dmy_date: str
|
||||
"""
|
||||
day, month, year = dmy_date.split(".")
|
||||
return f"{2000 + int(year)}-{month}-{day}"
|
||||
|
||||
|
||||
def czy_mecz_istnieje(self, zewnetrzne_id_meczu: str):
|
||||
# mecz = db.simple_select_all(ldb.mecze, zewnetrzne_id_meczu=zewnetrzne_id_meczu)
|
||||
# if mecz is not None and mecz != []:
|
||||
@@ -97,6 +110,9 @@ class scraper:
|
||||
# Jeśli nie, dodaj go w podobny sposób, jak
|
||||
# w sample_data_init() (w lewy_db.py).
|
||||
|
||||
id_zawodnika = self.db.get_id_zawodnika_by_zewnetrzne_id(zewnetrzne_id_sportowca)
|
||||
zawodnik = self.db.simple_select_all("sportowcy", zewnetrzne_id_zawodnika=zewnetrzne_id_sportowca)[0]
|
||||
|
||||
page = 0
|
||||
match_num = 0
|
||||
while not stop_scraping:
|
||||
@@ -141,8 +157,88 @@ class scraper:
|
||||
|
||||
# TODO: dodaj obiekt mecz do bazy (simple_insert_one(), simple_insert_many())
|
||||
print(f"{c.OKCYAN}Nowy mecz ({match_num}){c.ENDC}: {match}")
|
||||
|
||||
iso_converted_date = self.to_iso_compatible_date(safe_traverse(match, ["eventStartTime"], default="1970-01-01"))
|
||||
|
||||
self.db.simple_insert_one("mecze",
|
||||
zewnetrzne_id_meczu = safe_traverse(match, ["eventEncodedId"], default=""),
|
||||
data = iso_converted_date,
|
||||
gospodarze_id = home_club_id,
|
||||
gospodarze = self.db.simple_select_all("kluby", id_klubu=home_club_id)[0],
|
||||
goscie_id = away_club_id,
|
||||
goscie = self.db.simple_select_all("kluby", id_klubu=away_club_id)[0],
|
||||
gosp_wynik = safe_traverse(match, ["homeScore"], default=0),
|
||||
gosc_wynik = safe_traverse(match, ["awayScore"], default=0),
|
||||
sezon = safe_traverse(match, ["tournamentSeason"], default=""),
|
||||
nazwa_turnieju = safe_traverse(match, ["tournamentTitle"], default=""),
|
||||
skrocona_nazwa_turnieju = safe_traverse(match, ["tournamentTemplateShortCode"], default=""),
|
||||
flaga = safe_traverse(match, ["flagId"], default=0),
|
||||
)
|
||||
match_num += 1
|
||||
|
||||
stats = safe_traverse(match, ["stats"], default="")
|
||||
zewnetrzne_id_meczu = safe_traverse(match, ["eventEncodedId"], default="")
|
||||
|
||||
if stats != False: # gdy sportowiec był aktywny w meczu
|
||||
print("todo :)")
|
||||
# # TODO:
|
||||
# self.db.simple_insert_one("sportowcy_w_meczach",
|
||||
# id_zawodnika = id_zawodnika,
|
||||
# zawodnik = zawodnik,
|
||||
# zewnetrzne_id_meczu = zewnetrzne_id_meczu,
|
||||
# # ODTĄD SIĘ NIE POKRYWA!!! POLA POWINNY SIĘ ZGADZAĆ Z TYM, CO JEST W LEWY_DB (konkretnie klasie sportowcy_w_meczach)
|
||||
# ostatni_mecz = self.db.get_id_meczu_by_zewnetrzne_id(zewnetrzne_id_meczu),
|
||||
# ilosc_wystapien = 1 if int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")) > 0 else 0,
|
||||
# minut_gry = int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")),
|
||||
# gier_sum = 1 if int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")) > 0 else 0,
|
||||
# goli_sum = int(safe_traverse(stats, ["596", "value"], default="0")),
|
||||
# asyst_sum = int(safe_traverse(stats, ["541", "value"], default="0")),
|
||||
# interwencji_sum = 0,
|
||||
# nieobronionych_interwencji_sum = 0,
|
||||
# zoltych_kartek_sum = int(safe_traverse(stats, ["599", "value"], default="0")),
|
||||
# czerwonych_kartek_sum = int(safe_traverse(stats, ["600", "value"], default="0")),
|
||||
# wygranych_sum = 1 if safe_traverse(match, ["winLoseShort"], default="") == "Z" else 0,
|
||||
# wynik_sum = safe_traverse(match, ["rating"], default=0),
|
||||
# meczow_do_wynikow_sum = 1 if safe_traverse(match, ["rating"], default=0) not in (0, None) else None
|
||||
# )
|
||||
|
||||
# # analogicznie zinkrementuj statystyki_sportowcow:
|
||||
# # UWAGA! NIE ZADZIAŁA DLA NIKOGO INNEGO, NIŻ ROBERCIKA (bo nie mamy innych sportowców w bazie, trzeba dodać ich ręcznie w lewy_db sample_data_init())
|
||||
# self.db.simple_insert_one("statystyki_sportowcow",
|
||||
# sportowiec = zawodnik,
|
||||
# ostatni_mecz = self.db.get_id_meczu_by_zewnetrzne_id(zewnetrzne_id_meczu),
|
||||
# ilosc_wystapien = 1 if int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")) > 0 else 0,
|
||||
# minut_gry = int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")),
|
||||
# gier_sum = 1 if int(safe_traverse(stats, ["595", "value"], default="0").rstrip("'")) > 0 else 0,
|
||||
# goli_sum = int(safe_traverse(stats, ["596", "value"], default="0")),
|
||||
# asyst_sum = int(safe_traverse(stats, ["541", "value"], default="0")),
|
||||
# interwencji_sum = 0,
|
||||
# nieobronionych_interwencji_sum = 0,
|
||||
# zoltych_kartek_sum = int(safe_traverse(stats, ["599", "value"], default="0")),
|
||||
# czerwonych_kartek_sum = int(safe_traverse(stats, ["600", "value"], default="0")),
|
||||
# wygranych_sum = 1 if safe_traverse(match, ["winLoseShort"], default="") == "Z" else 0,
|
||||
# wynik_sum = safe_traverse(match, ["rating"], default=0),
|
||||
# meczow_do_wynikow_sum = 1 if safe_traverse(match, ["rating"], default=0) not in (0, None) else None
|
||||
# )
|
||||
|
||||
else:
|
||||
print("też todo :)")
|
||||
# # TODO: TU TEŻ TRZEBA POPRAWIĆ ANALOGICZNIE DO TEGO, CO JEST WEWNĄTRZ IF'A
|
||||
# self.db.simple_insert_one("sportowcy_w_meczach", id_zawodnika,
|
||||
# ostatni_mecz = self.db.get_id_meczu_by_zewnetrzne_id(zewnetrzne_id_meczu),
|
||||
# ilosc_wystapien = 0,
|
||||
# minut_gry = 0,
|
||||
# gier_sum = 0,
|
||||
# goli_sum = 0,
|
||||
# asyst_sum = 0,
|
||||
# interwencji_sum = 0,
|
||||
# nieobronionych_interwencji_sum = 0,
|
||||
# zoltych_kartek_sum = 0,
|
||||
# czerwonych_kartek_sum = 0,
|
||||
# wygranych_sum = 1 if safe_traverse(match, ["winLoseShort"], default="") == "Z" else 0,
|
||||
# wynik_sum = safe_traverse(match, ["rating"], default=0),
|
||||
# meczow_do_wynikow_sum = 1 if safe_traverse(match, ["rating"], default=0) not in (0, None) else None
|
||||
# )
|
||||
|
||||
# TODO: Zaktualizuj statystyki sportowca
|
||||
|
||||
@@ -155,7 +251,7 @@ class scraper:
|
||||
# rate limita. - sherl
|
||||
|
||||
page += 1
|
||||
time.sleep(15)
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
def aktualizuj_dane(self):
|
||||
|
||||
@@ -58,6 +58,8 @@ def setup():
|
||||
sanity_string += f" If you're running a reverse proxy, set {c.OKCYAN}is_proxied{c.ENDC} to true to silence this message.\n"
|
||||
print(sanity_string)
|
||||
|
||||
# Should fix disconnects: https://stackoverflow.com/a/61739721
|
||||
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {"pool_pre_ping": True}
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f"{config['general']['db_path_url']}"
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
|
||||
@@ -89,7 +89,12 @@ def get_matches(r):
|
||||
"""
|
||||
TODO: Zwraca mecze.
|
||||
"""
|
||||
pass
|
||||
response_json = []
|
||||
mecze = getDb().simple_select_all("mecze")
|
||||
for mecz in mecze:
|
||||
response_json.append(mecz.jsonify())
|
||||
print(response_json)
|
||||
return 200, "ok", response_json
|
||||
|
||||
# GET /api/v1/debugger_halt?token=XXX...
|
||||
@require_authentication
|
||||
@@ -142,7 +147,7 @@ def lookup(data, request):
|
||||
case 'halt':
|
||||
return debugger_halt(r = request)
|
||||
case 'matches':
|
||||
get_matches(r = request)
|
||||
return get_matches(r = request)
|
||||
case _:
|
||||
increment_bad_requests()
|
||||
return not_implemented(data)
|
||||
@@ -36,6 +36,9 @@ class baza():
|
||||
self.db = self.initDB(self.app, config)
|
||||
self.refresh_session()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Obiekt bazodanowy baza ({len(self.entities)} encji)>"
|
||||
|
||||
def initDB(self, app, config):
|
||||
global sportowcy, trofea, sportowcy_w_meczach, statystyki_sportowcow, kluby, mecze
|
||||
tnp = config['general']['db_prefix'] + "_lewangoalski_"
|
||||
@@ -119,6 +122,8 @@ class baza():
|
||||
zoltych_kartek_sum: Mapped[ int] = mapped_column()
|
||||
czerwonych_kartek_sum: Mapped[ int] = mapped_column()
|
||||
wygranych_sum: Mapped[ int] = mapped_column()
|
||||
przegranych_sum: Mapped[ int] = mapped_column()
|
||||
remisow_sum: Mapped[ int] = mapped_column()
|
||||
wynik_sum: Mapped[ int] = mapped_column()
|
||||
meczow_do_wynikow_sum: Mapped[ int] = mapped_column()
|
||||
|
||||
@@ -155,6 +160,23 @@ class baza():
|
||||
def __repr__(self):
|
||||
return f"<Mecz #{self.id_meczu} ({self.zewnetrzne_id_meczu}, {self.gospodarze.skrocona_nazwa} vs. {self.goscie.skrocona_nazwa})>"
|
||||
|
||||
def jsonify(self):
|
||||
return {
|
||||
"id_meczu": self.id_meczu,
|
||||
"zewnetrzne_id_meczu": self.zewnetrzne_id_meczu,
|
||||
"data": self.data.strftime("%Y-%m-%d"),
|
||||
"gospodarze_id": self.gospodarze_id,
|
||||
"gospodarze": self.gospodarze.skrocona_nazwa,
|
||||
"goscie_id": self.goscie_id,
|
||||
"goscie": self.goscie.skrocona_nazwa,
|
||||
"gosp_wynik": self.gosp_wynik,
|
||||
"gosc_wynik": self.gosc_wynik,
|
||||
"sezon": self.sezon,
|
||||
"nazwa_turnieju": self.nazwa_turnieju,
|
||||
"skrocona_nazwa_turnieju": self.skrocona_nazwa_turnieju,
|
||||
"flaga": self.flaga
|
||||
}
|
||||
|
||||
self.entities = {
|
||||
'sportowcy': sportowcy,
|
||||
'trofea': trofea,
|
||||
@@ -201,8 +223,10 @@ class baza():
|
||||
:param string: Zapis tekstowy
|
||||
:type string: str
|
||||
"""
|
||||
table_str = string[:string.find('.')]
|
||||
column_str = string[string.find('.') + 1:]
|
||||
try:
|
||||
table_str, column_str = string.split('.')
|
||||
except:
|
||||
raise ValueError("Nieprawidłowe dane - podaj zarówno tabelę, jak i kolumnę, np.: \"kluby.id_klubu\".")
|
||||
if hasattr(self.entities[table_str], column_str):
|
||||
return getattr(self.entities[table_str], column_str)
|
||||
return None
|
||||
@@ -222,27 +246,60 @@ class baza():
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
query_params, special_args = self.extract_special_args(kwargs)
|
||||
|
||||
print(f"[{round(time.time())}] SELECT {entity_type}")
|
||||
|
||||
results = (
|
||||
self.session.
|
||||
query(self.entities[entity_type]).
|
||||
filter_by(**query_params)
|
||||
)
|
||||
|
||||
# Obsługuje "ORDER_BY", "LIMIT", itp. itd.
|
||||
results = self.manipulate_results(results, special_args)
|
||||
|
||||
results_objs = results.all()
|
||||
print(f"[{round(time.time())}] SELECT RESULTS: {results_objs}")
|
||||
|
||||
return results_objs
|
||||
|
||||
def extract_special_args(self, dictionary: dict):
|
||||
"""
|
||||
Zwraca krotkę składającą się ze słowników z:
|
||||
- parametrami wyszukiwania
|
||||
- specjalnymi argumentami
|
||||
|
||||
:param dictionary: Słownik wejściowy
|
||||
:type dictionary: dict
|
||||
"""
|
||||
|
||||
# Save special arguments received with kwargs,
|
||||
# that are meant for SQL operations to special_args,
|
||||
# and delete from the rest, that will be passed
|
||||
# directly to filter_by().
|
||||
# They will not be passed as search query, but serve
|
||||
# as an additional search parameter.
|
||||
dictionary = dictionary.copy()
|
||||
|
||||
special_keywords = ("ORDER_BY", "ORDER_BY_DESC", "LIMIT")
|
||||
special_args = {}
|
||||
|
||||
for arg in special_keywords:
|
||||
if arg in kwargs:
|
||||
special_args[arg] = kwargs[arg]
|
||||
del kwargs[arg]
|
||||
if arg in dictionary:
|
||||
special_args[arg] = dictionary[arg]
|
||||
del dictionary[arg]
|
||||
|
||||
print(f"[{round(time.time())}] SELECT")
|
||||
return dictionary, special_args
|
||||
|
||||
results = (
|
||||
self.session.
|
||||
query(self.entities[entity_type]).
|
||||
filter_by(**kwargs)
|
||||
)
|
||||
def manipulate_results(self, results, special_args: dict):
|
||||
"""
|
||||
Wykonuje specjalne operacje na rezultatach wyszukiwania.
|
||||
|
||||
:param results: Wyniki wyszukiwania (ORM)
|
||||
:param special_args: Specjalne operacje
|
||||
:type special_args: dict
|
||||
"""
|
||||
|
||||
if "ORDER_BY" in special_args:
|
||||
column = self.str_to_column(special_args["ORDER_BY"])
|
||||
@@ -257,10 +314,7 @@ class baza():
|
||||
if "LIMIT" in special_args:
|
||||
results = results.limit(special_args["LIMIT"])
|
||||
|
||||
results_objs = results.all()
|
||||
print(f"[{round(time.time())}] SELECT RESULTS: {results_objs}")
|
||||
|
||||
return results_objs
|
||||
return results
|
||||
|
||||
@exit_gracefully
|
||||
def simple_insert_one(self, entity_type, **kwargs):
|
||||
@@ -283,7 +337,7 @@ class baza():
|
||||
f"Aby naprawić dodawanie z autoinkrementującym kluczem zobacz {c.WARNING}https://stackoverflow.com/a/8745101{c.ENDC}\n"
|
||||
f"Zostałeś ostrzeżony!")
|
||||
|
||||
print(f"[{round(time.time())}] INSERT")
|
||||
print(f"[{round(time.time())}] INSERT {entity_type}")
|
||||
|
||||
obj = self.entities[entity_type](**kwargs)
|
||||
#with Session(self.db.engine) as session:
|
||||
@@ -307,6 +361,131 @@ class baza():
|
||||
return 0
|
||||
#return 1
|
||||
|
||||
@exit_gracefully
|
||||
def increment_fields(self, entity_type, record_id, **increments):
|
||||
"""
|
||||
Dodaje wartości do istniejących pól (np. goli_sum += 2).
|
||||
|
||||
Użycie:
|
||||
increment_fields(ldb.statystyki_sportowcow, 123, goli_sum=2, asyst_sum=1)
|
||||
"""
|
||||
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
if entity_type not in self.entities:
|
||||
print(f"Nieznany typ encji: {entity_type}")
|
||||
return -1
|
||||
|
||||
model_class = self.entities[entity_type]
|
||||
|
||||
print(f"[{round(time.time())}] INCREMENT {entity_type}")
|
||||
|
||||
record = self.session.get(model_class, record_id)
|
||||
if not record:
|
||||
print(f"Rekord z ID {record_id} nie istnieje w tabeli {entity_type}")
|
||||
return -1
|
||||
|
||||
for key, increment_value in increments.items():
|
||||
if hasattr(record, key):
|
||||
current_value = getattr(record, key, 0)
|
||||
setattr(record, key, current_value + increment_value)
|
||||
else:
|
||||
print(f"⚠️ Pole '{key}' nie istnieje w modelu '{entity_type}' - pomijam.")
|
||||
|
||||
self.session.commit()
|
||||
return 0
|
||||
|
||||
@exit_gracefully
|
||||
def get_id_meczu_by_zewnetrzne_id(self, external_id: str) -> int | None:
|
||||
"""
|
||||
Zwraca id_meczu na podstawie zewnetrzne_id_meczu.
|
||||
|
||||
:param external_id: zewnętrzne ID meczu
|
||||
:return: id_meczu lub None jeśli nie znaleziono
|
||||
"""
|
||||
stmt = select(mecze.id_meczu).where(mecze.zewnetrzne_id_meczu == external_id)
|
||||
result = self.session.execute(stmt).scalar_one_or_none()
|
||||
return result
|
||||
|
||||
@exit_gracefully
|
||||
def get_id_zawodnika_by_zewnetrzne_id(self, external_id: str) -> int | None:
|
||||
"""
|
||||
Zwraca id_zawodnika na podstawie zewnetrzne_id_zawodnika.
|
||||
|
||||
:param external_id: zewnętrzne ID meczu
|
||||
:return: id_zawodnika lub None jeśli nie znaleziono
|
||||
"""
|
||||
stmt = select(sportowcy.id_zawodnika).where(sportowcy.zewnetrzne_id_zawodnika == external_id)
|
||||
result = self.session.execute(stmt).scalar_one_or_none()
|
||||
return result
|
||||
|
||||
@exit_gracefully
|
||||
def simple_update_one(self, entity_type, record_id, **kwargs):
|
||||
"""
|
||||
Użycie:
|
||||
simple_update_one(ldb.kluby, "polska", pelna_nazwa="Nowa Nazwa", skrocona_nazwa="NN")
|
||||
|
||||
Aktualizuje pojedynczy rekord w bazie danych na podstawie ID.
|
||||
"""
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
if entity_type not in self.entities:
|
||||
print(f"Nieznany typ encji: {entity_type}")
|
||||
return -1
|
||||
|
||||
model_class = self.entities[entity_type]
|
||||
|
||||
print(f"[{round(time.time())}] UPDATE {entity_type}")
|
||||
|
||||
record = self.session.get(model_class, record_id)
|
||||
if not record:
|
||||
print(f"Rekord z ID {record_id} nie istnieje w tabeli {entity_type}")
|
||||
return -1
|
||||
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(record, key):
|
||||
setattr(record, key, value)
|
||||
else:
|
||||
print(f"⚠️ Pole '{key}' nie istnieje w modelu '{entity_type}' - pomijam.")
|
||||
|
||||
self.session.commit()
|
||||
return 0
|
||||
|
||||
@exit_gracefully
|
||||
def dodaj_sportowca_w_meczu(self, entity_type, record_id, **kwargs):
|
||||
"""
|
||||
Użycie:
|
||||
dodaj_sportowca_w_meczu(ldb.sportowcy_w_meczu, ...)
|
||||
|
||||
Dodaje pojedynczy rekord w bazie danych.
|
||||
"""
|
||||
if not isinstance(entity_type, str):
|
||||
entity_type = entity_type.__name__
|
||||
|
||||
if entity_type not in self.entities:
|
||||
print(f"Nieznany typ encji: {entity_type}")
|
||||
return -1
|
||||
|
||||
model_class = self.entities[entity_type]
|
||||
|
||||
print(f"[{round(time.time())}] INSERT {entity_type}")
|
||||
|
||||
record = self.session.get(model_class, record_id)
|
||||
if not record:
|
||||
print(f"Rekord z ID {record_id} nie istnieje w tabeli {entity_type}")
|
||||
return -1
|
||||
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(record, key):
|
||||
setattr(record, key, value)
|
||||
else:
|
||||
print(f"⚠️ Pole '{key}' nie istnieje w modelu '{entity_type}' - pomijam.")
|
||||
|
||||
self.session.commit()
|
||||
return 0
|
||||
|
||||
@exit_gracefully
|
||||
def sample_data_init(self, override_safety_check=False):
|
||||
"""
|
||||
@@ -340,7 +519,7 @@ class baza():
|
||||
goscie_id="undefined",
|
||||
gosp_wynik=0,
|
||||
gosc_wynik=0,
|
||||
sezon="1970/1970",
|
||||
sezon="1970-1970",
|
||||
nazwa_turnieju="Nieznany turniej",
|
||||
skrocona_nazwa_turnieju="N/A",
|
||||
flaga=0)
|
||||
@@ -356,6 +535,8 @@ class baza():
|
||||
zoltych_kartek_sum=0,
|
||||
czerwonych_kartek_sum=0,
|
||||
wygranych_sum=0,
|
||||
przegranych_sum=0,
|
||||
remisow_sum=0,
|
||||
wynik_sum=0,
|
||||
meczow_do_wynikow_sum=0)
|
||||
|
||||
@@ -374,7 +555,7 @@ class baza():
|
||||
wycena=64_940_000)
|
||||
trofeum = trofea(
|
||||
nazwa="Nieznane trofeum",
|
||||
sezon="0000/0000",
|
||||
sezon="0000-0000",
|
||||
rok=1970)
|
||||
|
||||
session.add(sportowiec)
|
||||
@@ -386,6 +567,40 @@ class baza():
|
||||
trofeum.zawodnik = sportowiec
|
||||
sportowiec.ostatnie_trofeum = trofeum
|
||||
|
||||
# MIEJSCE NA DANE KOLEJNYCH SPORTOWCÓW
|
||||
# TRZEBA ZROBIĆ TO RĘCZNIE, ZGODNIE ZE SCHEMATEM:
|
||||
# self.simple_insert_one(statystyki_sportowcow,
|
||||
# ostatni_mecz=1,
|
||||
# ilosc_wystapien=0,
|
||||
# minut_gry=0,
|
||||
# gier_sum=0,
|
||||
# goli_sum=0,
|
||||
# asyst_sum=0,
|
||||
# interwencji_sum=0,
|
||||
# nieobronionych_interwencji_sum=0,
|
||||
# zoltych_kartek_sum=0,
|
||||
# czerwonych_kartek_sum=0,
|
||||
# wygranych_sum=0,
|
||||
# przegranych_sum=0,
|
||||
# remisow_sum=0,
|
||||
# wynik_sum=0,
|
||||
# meczow_do_wynikow_sum=0)
|
||||
|
||||
# self.simple_insert_one(sportowcy,
|
||||
# zewnetrzne_id_zawodnika="...",
|
||||
# imie="...",
|
||||
# nazwisko="...",
|
||||
# data_urodzenia="...",
|
||||
# czy_aktywny=True, # NIE WSZYSCY SĄ AKTYWNI!
|
||||
# klub_id="undefined",
|
||||
# narodowosc="...",
|
||||
# ilosc_trofeow=0,
|
||||
# pierwszy_mecz_id=1,
|
||||
# ostatni_gol_dla_id="undefined",
|
||||
# statystyki_id=2, # itd...
|
||||
# wycena=...) # w złotówkach
|
||||
|
||||
session.commit()
|
||||
return 0
|
||||
return 1
|
||||
|
||||
return 1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from git import Repo # hash ostatniego commitu
|
||||
#from git import Repo # hash ostatniego commitu
|
||||
import os
|
||||
import time
|
||||
import toml
|
||||
@@ -36,11 +36,11 @@ def getCommit() -> str | None:
|
||||
return None
|
||||
|
||||
def getCommitInFormattedHTML():
|
||||
repo = "<p>Brak informacji o wersji skryptu</p>"
|
||||
repo = "<center><p style=\"color: white;\">Brak informacji o wersji skryptu</p></center>"
|
||||
commit = getCommit()
|
||||
|
||||
if commit is not None:
|
||||
repo = f"<p>Commit: <a href='https://gitea.7o7.cx/roberteam/lewangoalski/commit/{commit}'>{commit[:11]}</a></p>"
|
||||
repo = f"<center><p style=\"color: white;\">Commit: <a href='https://gitea.7o7.cx/roberteam/lewangoalski/commit/{commit}'>{commit[:11]}</a></p></center>"
|
||||
|
||||
return repo
|
||||
|
||||
@@ -155,4 +155,4 @@ config = {}
|
||||
configfile = "config.toml"
|
||||
version = getCommitWithFailsafe()
|
||||
apiVersion = "1"
|
||||
randomly_generated_passcode = 0
|
||||
randomly_generated_passcode = 0
|
||||
|
||||
@@ -6,33 +6,33 @@ import lewy_globals
|
||||
def get_lewy_stats():
|
||||
return {
|
||||
'all_time_stats': {
|
||||
'goals': 380,
|
||||
'assists': 120,
|
||||
'matches': 450,
|
||||
'goals': 589+78,
|
||||
'assists':154+21,
|
||||
'matches': 791+136,
|
||||
},
|
||||
'club_stats': {
|
||||
'goals': 132,
|
||||
'assists': 112,
|
||||
'matches': 245,
|
||||
'goals': 589,
|
||||
'assists': 154,
|
||||
'matches': 791,
|
||||
},
|
||||
'nation_stats': {
|
||||
'goals': 86,
|
||||
'assists': 52,
|
||||
'matches': 158,
|
||||
'goals': 78,
|
||||
'assists': 21,
|
||||
'matches': 136,
|
||||
},
|
||||
'worldcup': {
|
||||
'goals': 7,
|
||||
'assists': 2,
|
||||
'matches': 11,
|
||||
'international_cups': {
|
||||
'goals': 110,
|
||||
'assists': 19,
|
||||
'matches': 152,
|
||||
},
|
||||
'euro': {
|
||||
'goals': 6,
|
||||
'assists': 2,
|
||||
'matches': 18,
|
||||
'national_cups': {
|
||||
'goals': 58,
|
||||
'assists': 4,
|
||||
'matches': 74,
|
||||
},
|
||||
'cards': {
|
||||
'yellow': 24,
|
||||
'red': 4,
|
||||
'yellow': 86,
|
||||
'red': 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,28 @@ def index():
|
||||
|
||||
def mecze():
|
||||
# Możesz dostarczyć szczegóły dotyczące meczów
|
||||
selected_date = request.args.get("date", 2024)
|
||||
matches = [
|
||||
{'date': '2024-10-12', 'opponent': 'Real Madrid', 'goals': 2, 'assists': 1, 'minutes': 90},
|
||||
{'date': '2024-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2023-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2022-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2021-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2020-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
{'date': '2019-10-19', 'opponent': 'Valencia', 'goals': 1, 'assists': 0, 'minutes': 85},
|
||||
|
||||
]
|
||||
return render_template('matches.html', matches=matches)
|
||||
|
||||
@@ -71,18 +90,24 @@ def statystyki():
|
||||
def clubs():
|
||||
selected_club = request.args.get("club","FC Barcelona")
|
||||
clubs = [
|
||||
{'club': 'FC Barcelona', 'goals': 22,'assist':12},
|
||||
{'club': 'Bayern Monachium', 'goals': 132,'assist':12},
|
||||
{'club': 'Borussia Dortmund', 'goals': 132,'assist':12},
|
||||
{'club': 'Lech Poznan', 'goals': 132,'assist':12},
|
||||
{'club': 'FC Barcelona', 'goals': 101,'assist':20, 'matches':147,'minutes_played': 11684,'yellow_card':12,'red_card': 1, 'wins':101, 'draws': 14,'lost': 32},
|
||||
{'club': 'Bayern Monachium', 'goals': 344,'assist':73,'matches':375,'minutes_played': 31759,'yellow_card':36,'red_card': 0, 'wins':307, 'draws': 35,'lost': 33},
|
||||
{'club': 'Borussia Dortmund', 'goals': 103,'assist':42,'matches':187,'minutes_played': 14374,'yellow_card':19,'red_card': 1, 'wins':120, 'draws': 40,'lost': 27},
|
||||
{'club': 'Lech Poznan', 'goals': 41,'assist':19,'matches':82,'minutes_played': 6858,'yellow_card':9,'red_card': 0, 'wins':'-', 'draws': '-','lost': '-'},
|
||||
]
|
||||
return render_template('club.html', clubs=clubs, selected_club=selected_club)
|
||||
|
||||
def representation():
|
||||
nation_stats = {
|
||||
'goals': 86,
|
||||
'assists': 52,
|
||||
'goals': 85,
|
||||
'assists': 35,
|
||||
'matches': 158,
|
||||
'minutes_played': 12108,
|
||||
'yellow_card':10,
|
||||
'red_card': 0,
|
||||
'wins':75,
|
||||
'draws': 35,
|
||||
'lost': 48
|
||||
}
|
||||
return render_template('representation.html', nation_stats=nation_stats)
|
||||
def compare():
|
||||
|
||||
@@ -386,34 +386,6 @@ header button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px){
|
||||
.section__matches
|
||||
{
|
||||
font-size: 10px;
|
||||
}
|
||||
.section__matches th{
|
||||
padding: 3px;
|
||||
}
|
||||
.club-stats-grid
|
||||
{
|
||||
grid-template-columns: 1fr 1fr !important;
|
||||
}
|
||||
.club-stats-grid .stat-box
|
||||
{
|
||||
width: 100%;
|
||||
}
|
||||
.section-stats-center .section-stats .stats
|
||||
{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.section-stats-center .section-stats .stats .stat-box
|
||||
{
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,25 +33,25 @@
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ stats.assist }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ stats.goals }} </span>
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ stats.matches }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ stats.minutes_played }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Hat-tricki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ stats.yellow_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ stats.red_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ stats.wins }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Remisy:</p> <span class="stat-box-special"> {{ stats.draws }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ stats.goals }}</span>
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ stats.lost }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -11,28 +11,28 @@
|
||||
<p>Gole:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assist }} </span>
|
||||
<p>Asysty:</p> <span class="stat-box-special"> {{ nation_stats.assists }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Występy:</p> <span class="stat-box-special"> {{ nation_stats.goals }} </span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Łączny czas gry:</p> <span class="stat-box-special"> {{ nation_stats.minutes_played }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Hat-tricki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ nation_stats.yellow_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ nation_stats.red_card }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Zwycięstwa:</p> <span class="stat-box-special"> {{ nation_stats.wins }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Żółte kartki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Remisy:</p> <span class="stat-box-special"> {{ nation_stats.draws }}</span>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<p>Czerwone kartki:</p> <span class="stat-box-special"> {{ nation_stats.goals }}</span>
|
||||
<p>Porażki:</p> <span class="stat-box-special"> {{ nation_stats.lost }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -56,35 +56,35 @@
|
||||
</div>
|
||||
</section>
|
||||
<section class="section-stats">
|
||||
<h2>Mistrzostwa świata</h2>
|
||||
<h2>Puchary międzynarodowe</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.goals }}</h3>
|
||||
<h3>{{ international_cups.goals }}</h3>
|
||||
<p>Gole</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.assists }}</h3>
|
||||
<h3>{{ international_cups.assists }}</h3>
|
||||
<p>Asysty</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ worldcup.matches }}</h3>
|
||||
<h3>{{ international_cups.matches }}</h3>
|
||||
<p>Występy</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section-stats">
|
||||
<h2>EURO</h2>
|
||||
<h2>Puchary krajowe</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.goals }}</h3>
|
||||
<h3>{{ national_cups.goals }}</h3>
|
||||
<p>Gole</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.assists }}</h3>
|
||||
<h3>{{ national_cups.assists }}</h3>
|
||||
<p>Asysty</p>
|
||||
</div>
|
||||
<div class="stat-box">
|
||||
<h3>{{ euro.matches }}</h3>
|
||||
<h3>{{ national_cups.matches }}</h3>
|
||||
<p>Występy</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
BIN
FlaskWebProject/instance/lewangoalski.sqlite
Normal file
BIN
FlaskWebProject/instance/lewangoalski.sqlite
Normal file
Binary file not shown.
Reference in New Issue
Block a user