Files
lewangoalski/FlaskWebProject/FlaskWebProject/lewy_routes.py

109 lines
3.2 KiB
Python

from flask import render_template, request, make_response
import lewy_api_v1
import lewy_db
import lewy_globals
def get_lewy_stats():
return {
'all_time_stats': {
'goals': 380,
'assists': 120,
'matches': 450,
},
'club_stats': {
'goals': 132,
'assists': 112,
'matches': 245,
},
'nation_stats': {
'goals': 86,
'assists': 52,
'matches': 158,
},
'worldcup': {
'goals': 7,
'assists': 2,
'matches': 11,
},
'euro': {
'goals': 6,
'assists': 2,
'matches': 18,
},
'cards': {
'yellow': 24,
'red': 4,
}
}
def index():
dark_mode = request.cookies.get('darkMode', 'disabled')
# Przykładowe użycie endpointu last_goal_for():
# roberts_last_goals_club = lewy_api_v1.last_goal_for()
# print(roberts_last_goals_club.id_klubu)
stats = {
'goals': 38,
'assists': 12,
'matches': 45,
'matches_list': [
{'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},
# Możesz dodać więcej meczów...
]
}
return render_template('index.html', goals=stats['goals'], assists=stats['assists'],
matches=stats['matches'], matches_list=stats['matches_list'],
commit_in_html=lewy_globals.getCommitInFormattedHTML(),
dark_mode=dark_mode)
def mecze():
# Możesz dostarczyć szczegóły dotyczące meczów
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},
]
return render_template('matches.html', matches=matches)
def statystyki():
dane=get_lewy_stats()
return render_template('stats.html', **dane)
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},
]
return render_template('club.html', clubs=clubs, selected_club=selected_club)
def representation():
nation_stats = {
'goals': 86,
'assists': 52,
'matches': 158,
}
return render_template('representation.html', nation_stats=nation_stats)
def compare():
selected_player = request.args.get("player","Leo Messi")
lewy=get_lewy_stats()
player2 = [
{'name':'Leo Messi','goals': 34,'assists': 12},
]
return render_template('compare.html',player2=player2, selected_player=selected_player,**lewy, )
def trophies():
trophy = [
{'name': 'asdasd', 'year': 2023},
{'name': 'ssss', 'sezon': '2022/2023'},
]
return render_template('trophies.html',trophy=trophy)
def toggle_dark_mode():
# Przełącz tryb i zapisz w ciasteczku
dark_mode = request.cookies.get('darkMode', 'disabled')
new_mode = 'enabled' if dark_mode == 'disabled' else 'disabled'
response = make_response("OK")
response.set_cookie('darkMode', new_mode, max_age=31536000) # Ustawienie ciasteczka na 1 rok
return response