-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcli.py
More file actions
734 lines (626 loc) · 24.7 KB
/
cli.py
File metadata and controls
734 lines (626 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/usr/bin/env python3
"""
Fantacalcio-PY CLI - Modern command line interface for fantacalcio analysis
"""
import os
import sys
from pathlib import Path
from typing import Optional
import click
from loguru import logger
from rich.console import Console
from rich.table import Table
from rich import print as rprint
from rich.progress import (
Progress,
SpinnerColumn,
TextColumn,
BarColumn,
TaskProgressColumn,
TimeRemainingColumn,
MofNCompleteColumn,
)
from rich.panel import Panel
from rich.layout import Layout
from rich.live import Live
# Import existing modules
import data_retriever
import data_processor
import convenienza_calculator
import fuzzy_matcher
import config
import json
from datetime import datetime
console = Console()
def _get_file_age_info(file_path):
"""Get human-readable file age information"""
if not os.path.exists(file_path):
return None
file_time = datetime.fromtimestamp(os.path.getmtime(file_path))
now = datetime.now()
age = now - file_time
days = age.days
hours = age.seconds // 3600
if days > 0:
if days == 1:
age_str = "1 day"
else:
age_str = f"{days} days"
elif hours > 0:
if hours == 1:
age_str = "1 hour"
else:
age_str = f"{hours} hours"
else:
age_str = "less than 1 hour"
date_str = file_time.strftime("%Y-%m-%d %H:%M")
return {"age": age_str, "date": date_str, "days": days}
@click.group()
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose logging")
@click.pass_context
def cli(ctx, verbose):
"""
🏆 Fantacalcio-PY - Advanced fantasy football analysis tool
Analyze player data from multiple sources to find the best value picks
for your fantasy football auction.
"""
ctx.ensure_object(dict)
ctx.obj["verbose"] = verbose
# Configure logging
logger.remove() # Remove default handler
if verbose:
logger.add(
sys.stderr,
level="DEBUG",
format="<green>{time:HH:mm:ss}</green> | <level>{level: <8}</level> | {message}",
)
else:
logger.add(
sys.stderr, level="INFO", format="<level>{level: <8}</level> | {message}"
)
@cli.command()
@click.option(
"--source",
"-s",
type=click.Choice(["fpedia", "fstats", "all"]),
default="all",
help="Data source to scrape",
)
@click.option(
"--force", "-f", is_flag=True, help="Force re-download even if cache exists"
)
@click.pass_context
def scrape(ctx, source, force):
"""
📥 Download player data from external sources
Scrapes data from FPEDIA and/or FSTATS depending on the source option.
Uses intelligent caching to avoid unnecessary requests.
"""
verbose = ctx.obj.get("verbose", False)
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console,
) as progress:
# Setup directories
task = progress.add_task("Setting up directories...", total=None)
os.makedirs(config.DATA_DIR, exist_ok=True)
os.makedirs(config.OUTPUT_DIR, exist_ok=True)
progress.update(task, completed=True)
if source in ["fpedia", "all"]:
task = progress.add_task("Scraping FPEDIA data...", total=None)
try:
if force or not os.path.exists(config.GIOCATORI_CSV):
data_retriever.scrape_fpedia(force)
rprint("✅ [green]FPEDIA data scraped successfully[/green]")
else:
# Show cache age info
age_info = _get_file_age_info(config.GIOCATORI_CSV)
if age_info:
rprint(f"📁 [yellow]Using cached FPEDIA data from {age_info['date']} ({age_info['age']} old)[/yellow]")
if age_info['days'] >= 7:
rprint("⚠️ [orange]Data is over a week old - consider using --force for fresh data[/orange]")
elif age_info['days'] >= 1:
rprint("💡 [blue]Tip: Use --force to download latest data[/blue]")
else:
rprint("ℹ️ [yellow]Using cached FPEDIA data (use --force to re-download)[/yellow]")
progress.update(task, completed=True)
except Exception as e:
rprint(f"❌ [red]Error scraping FPEDIA: {e}[/red]")
if source in ["fstats", "all"]:
task = progress.add_task("Fetching FSTATS data...", total=None)
try:
if force or not os.path.exists(config.PLAYERS_CSV):
data_retriever.fetch_FSTATS_data(force)
rprint("✅ [green]FSTATS data fetched successfully[/green]")
else:
# Show cache age info
age_info = _get_file_age_info(config.PLAYERS_CSV)
if age_info:
rprint(f"📁 [yellow]Using cached FSTATS data from {age_info['date']} ({age_info['age']} old)[/yellow]")
if age_info['days'] >= 7:
rprint("⚠️ [orange]Data is over a week old - consider using --force for fresh data[/orange]")
elif age_info['days'] >= 1:
rprint("💡 [blue]Tip: Use --force to download latest data[/blue]")
else:
rprint("ℹ️ [yellow]Using cached FSTATS data (use --force to re-download)[/yellow]")
progress.update(task, completed=True)
except Exception as e:
rprint(f"❌ [red]Error fetching FSTATS: {e}[/red]")
@cli.command()
@click.option(
"--source",
"-s",
type=click.Choice(["fpedia", "fstats", "all"]),
default="all",
help="Data source to analyze",
)
@click.option("--output", "-o", type=click.Path(), default=None, help="Custom output directory")
@click.option("--top", "-t", type=int, default=50, help="Show top N players in summary")
@click.pass_context
def analyze(ctx, source, output, top):
"""
🔍 Process and analyze player data
Calculates convenience indexes and generates Excel reports with
detailed player analysis and recommendations.
"""
verbose = ctx.obj.get("verbose", False)
if output:
config.OUTPUT_DIR = output
os.makedirs(output, exist_ok=True)
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console,
) as progress:
# Load data
task = progress.add_task("Loading data files...", total=None)
df_fpedia, df_fstats = data_processor.load_dataframes()
progress.update(task, completed=True)
# Store final dataframes for unified analysis
df_fpedia_final = None
df_fstats_final = None
# Process FPEDIA
if source in ["fpedia", "all"] and not df_fpedia.empty:
task = progress.add_task("Processing FPEDIA data...", total=None)
df_processed = data_processor.process_fpedia_data(df_fpedia)
df_final = convenienza_calculator.calcola_convenienza_fpedia(df_processed)
# Save results
output_path = os.path.join(config.OUTPUT_DIR, "fpedia_analysis.xlsx")
df_final_sorted = df_final.sort_values(
by="Convenienza Potenziale", ascending=False
)
# Define comprehensive columns for output (EXACT copy from main.py)
output_columns = [
# Key Info
"Nome",
"Ruolo",
"Squadra",
# Calculated Indexes
"Convenienza Potenziale",
"Convenienza",
"Punteggio",
# Current Season Stats
f"Fantamedia anno {config.ANNO_CORRENTE-1}-{config.ANNO_CORRENTE}",
f"Presenze campionato corrente",
# Previous Season Stats
f"Fantamedia anno {config.ANNO_CORRENTE-2}-{config.ANNO_CORRENTE-1}",
"Partite giocate",
# Qualitative Info
"Trend",
"Skills",
"Consigliato prossima giornata",
"Buon investimento",
"Resistenza infortuni",
"Infortunato",
# Legacy
f"FM su tot gare {config.ANNO_CORRENTE-1}-{config.ANNO_CORRENTE}",
"Presenze previste",
"Gol previsti",
"Assist previsti",
"Nuovo acquisto",
]
final_columns = [
col for col in output_columns if col in df_final_sorted.columns
]
# Save both Excel and JSON
excel_path, json_path = _save_analysis_results(
df_final_sorted[final_columns], "fpedia_analysis", "fpedia"
)
progress.update(task, completed=True)
rprint(f"✅ [green]FPEDIA analysis saved to {excel_path}[/green]")
rprint(f"📄 [blue]JSON export saved to {json_path}[/blue]")
# Store for unified analysis
df_fpedia_final = df_final.copy()
# Show top players
_show_top_players(df_final_sorted, "FPEDIA", top)
# Process FSTATS
if source in ["fstats", "all"] and not df_fstats.empty:
task = progress.add_task("Processing FSTATS data...", total=None)
df_processed = data_processor.process_FSTATS_data(df_fstats)
df_final = convenienza_calculator.calcola_convenienza_FSTATS(df_processed)
# Save results
output_path = os.path.join(config.OUTPUT_DIR, "FSTATS_analysis.xlsx")
df_final_sorted = df_final.sort_values(
by="Convenienza Potenziale", ascending=False
)
# Define comprehensive columns for output (EXACT copy from main.py)
output_columns = [
# Key Info
"Nome",
"Ruolo",
"Squadra",
# Calculated Indexes
"Convenienza Potenziale",
"Convenienza",
"fantacalcioFantaindex",
# Key Performance Indicators
"fanta_avg",
"avg",
"presences",
# Core Stats
"goals",
"assists",
# Potential Stats
"xgFromOpenPlays",
"xA",
# Disciplinary
"yellowCards",
"redCards",
# Legacy
"injured",
"banned",
"mantra_position",
"fantacalcio_position",
"birth_date",
"foot_name",
"fantacalcioPlayerId",
"fantacalcioTeamName",
"appearances",
"matchesInStart",
"mins_played",
"pagella",
"fantacalcioRanking",
"fantacalcioFantaindex",
"fantacalcioPosition",
"goals90min",
"goalsFromOpenPlays",
"xgFromOpenPlays/90min",
"xA90min",
"successfulPenalties",
"penalties",
"gkPenaltiesSaved",
"gkCleanSheets",
"gkConcededGoals",
"openPlaysGoalsConceded",
"openPlaysXgConceded",
"fantamediaPred",
"fantamediaPredRoundId",
"matchConvocation",
"matchesWithGrade",
"perc_matchesStarted",
"perc_matchesWithGrade",
"percMinsPlayed",
"expectedFantamediaMean",
"External_breakout_Index",
"Shot_on_goal_Index",
"Offensive_actions_Index",
"Pass_forward_accuracy_Index",
"Air_challenge_offensive_Index",
"Cross_accuracy_Index",
"Converge_in_the_center_Index",
"Accompany_the_offensive_action_Index",
"Offensive_verticalization_Index",
"Received_pass_Index",
"Attacking_area_Index",
"Offensive_field_presence_Index",
"Pass_accuracy_Index",
"Pass_leading_chances_Index",
"Deep_runs_Index",
"Defense_solidity_Index",
"Set_piece_attack_Index",
"Shot_on_target_Index",
"Dribbles_successful_Index",
]
final_columns = [
col for col in output_columns if col in df_final_sorted.columns
]
# Save both Excel and JSON
excel_path, json_path = _save_analysis_results(
df_final_sorted[final_columns], "FSTATS_analysis", "fstats"
)
progress.update(task, completed=True)
rprint(f"✅ [green]FSTATS analysis saved to {excel_path}[/green]")
rprint(f"📄 [blue]JSON export saved to {json_path}[/blue]")
# Store for unified analysis
df_fstats_final = df_final.copy()
# Show top players
_show_top_players(df_final_sorted, "FSTATS", top)
# Create unified analysis if both datasets were processed
if (source == "all" and
df_fpedia_final is not None and df_fstats_final is not None):
task = progress.add_task("Creating unified analysis...", total=None)
# Create unified dataset using already processed data
df_unified = _merge_datasets_with_mapping(df_fpedia_final, df_fstats_final)
if not df_unified.empty:
# Sort unified dataset by fpedia convenience (prioritize fpedia scoring)
sort_cols = ["fpedia_Convenienza Potenziale", "fstats_Convenienza Potenziale"]
available_sort_cols = [col for col in sort_cols if col in df_unified.columns]
if available_sort_cols:
df_unified_sorted = df_unified.sort_values(by=available_sort_cols[0], ascending=False)
else:
df_unified_sorted = df_unified
# Save unified results
excel_path, json_path = _save_analysis_results(
df_unified_sorted, "unified_analysis", "unified"
)
progress.update(task, completed=True)
rprint(f"✅ [green]Unified analysis saved to {excel_path}[/green]")
rprint(f"📄 [blue]JSON export saved to {json_path}[/blue]")
# Show top unified players
_show_top_players(df_unified_sorted, "UNIFIED", top)
else:
progress.update(task, completed=True)
rprint("⚠️ [yellow]Unified analysis resulted in empty dataset[/yellow]")
@cli.command()
@click.option(
"--source",
"-s",
type=click.Choice(["fpedia", "fstats", "all"]),
default="all",
help="Data source for full pipeline",
)
@click.option("--force-scrape", is_flag=True, help="Force re-download of data")
@click.option("--top", "-t", type=int, default=20, help="Show top N players in summary")
@click.pass_context
def run(ctx, source, force_scrape, top):
"""
🚀 Run the complete analysis pipeline
Executes scraping, processing, and analysis in one command.
This is equivalent to running 'scrape' followed by 'analyze'.
"""
rprint("🏆 [bold blue]Starting Fantacalcio-PY Analysis Pipeline[/bold blue]")
# Run scraping
ctx.invoke(scrape, source=source, force=force_scrape)
# Run analysis
ctx.invoke(analyze, source=source, top=top)
rprint("🎉 [bold green]Pipeline completed successfully![/bold green]")
@cli.command()
@click.option(
"--source",
"-s",
type=click.Choice(["fpedia", "fstats"]),
required=True,
help="Data source to inspect",
)
@click.option("--role", "-r", help="Filter by player role (e.g., Portieri, Difensori)")
@click.option("--team", help="Filter by team name")
@click.option("--limit", "-l", type=int, default=10, help="Number of players to show")
def inspect(source, role, team, limit):
"""
🔍 Inspect loaded data without full analysis
Quick preview of the data to verify scraping worked correctly
and explore player information before running analysis.
"""
df_fpedia, df_fstats = data_processor.load_dataframes()
if source == "fpedia":
df = df_fpedia
if df.empty:
rprint(
"❌ [red]No FPEDIA data found. Run 'fantacalcio scrape' first.[/red]"
)
return
else:
df = df_fstats
if df.empty:
rprint(
"❌ [red]No FSTATS data found. Run 'fantacalcio scrape' first.[/red]"
)
return
# Apply filters
if role and "Ruolo" in df.columns:
df = df[df["Ruolo"].str.contains(role, case=False, na=False)]
if team and "Squadra" in df.columns:
df = df[df["Squadra"].str.contains(team, case=False, na=False)]
# Show results
total_players = len(df)
df_display = df.head(limit)
rprint(f"\n📊 [bold]{source.upper()} Data Preview[/bold]")
rprint(f"Total players: {total_players}")
if role:
rprint(f"Filtered by role: {role}")
if team:
rprint(f"Filtered by team: {team}")
# Create a nice table
table = Table(show_header=True, header_style="bold magenta")
# Add key columns
key_cols = ["Nome", "Ruolo", "Squadra"]
if source == "fpedia":
key_cols.extend(["Punteggio", "Presenze campionato corrente"])
else:
key_cols.extend(["fanta_avg", "presences"])
for col in key_cols:
if col in df_display.columns:
table.add_column(col)
for _, row in df_display.iterrows():
values = []
for col in key_cols:
if col in row:
val = str(row[col]) if pd.notna(row[col]) else "-"
values.append(val)
if values:
table.add_row(*values)
console.print(table)
@cli.command()
def status():
"""
📋 Show current data status and configuration
Displays information about available data files, configuration,
and system status to help with troubleshooting.
"""
table = Table(
title="Fantacalcio-PY Status", show_header=True, header_style="bold cyan"
)
table.add_column("Component", style="cyan")
table.add_column("Status", justify="center")
table.add_column("Details")
# Check data files
fpedia_exists = os.path.exists(config.GIOCATORI_CSV)
fpedia_size = os.path.getsize(config.GIOCATORI_CSV) if fpedia_exists else 0
fstats_exists = os.path.exists(config.PLAYERS_CSV)
fstats_size = os.path.getsize(config.PLAYERS_CSV) if fstats_exists else 0
table.add_row(
"FPEDIA Data",
"✅ Ready" if fpedia_exists and fpedia_size > 0 else "❌ Missing",
f"{fpedia_size // 1024} KB" if fpedia_exists else "Not found",
)
table.add_row(
"FSTATS Data",
"✅ Ready" if fstats_exists and fstats_size > 0 else "❌ Missing",
f"{fstats_size // 1024} KB" if fstats_exists else "Not found",
)
# Check output directory
output_exists = os.path.exists(config.OUTPUT_DIR)
table.add_row(
"Output Directory",
"✅ Ready" if output_exists else "❌ Missing",
config.OUTPUT_DIR,
)
# Check .env file
env_exists = os.path.exists(".env")
table.add_row(
"Environment Config",
"✅ Found" if env_exists else "⚠️ Missing",
".env file for FSTATS credentials",
)
# Configuration
table.add_row("Current Season", "ℹ️", str(config.ANNO_CORRENTE))
table.add_row("FSTATS Season", "ℹ️", str(config.FSTATS_ANNO))
console.print(table)
if not env_exists:
rprint("\n⚠️ [yellow]Warning: .env file not found![/yellow]")
rprint(
"Create a .env file with your FSTATS credentials to enable FSTATS data fetching."
)
def _save_analysis_results(df, base_name, source_name):
"""Helper function to save analysis results in both Excel and JSON formats"""
import pandas as pd
# Excel output
excel_path = os.path.join(config.OUTPUT_DIR, f"{base_name}.xlsx")
df.to_excel(excel_path, index=False)
# JSON output
json_path = os.path.join(config.OUTPUT_DIR, f"{base_name}.json")
data = {
"metadata": {
"source": source_name,
"total_players": len(df),
"generated_at": pd.Timestamp.now().isoformat(),
"columns": list(df.columns)
},
"players": df.fillna("").to_dict("records")
}
with open(json_path, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
return excel_path, json_path
def _merge_datasets_with_mapping(df_fpedia_final, df_fstats_final, mapping_file=fuzzy_matcher.OUTPUT_FILE):
"""Merge datasets using fuzzy mapping"""
import pandas as pd
# Load mapping
if not os.path.exists(mapping_file):
rprint(f"⚠️ [yellow]Mapping file {mapping_file} not found. Skipping unified analysis.[/yellow]")
return pd.DataFrame()
with open(mapping_file, "r", encoding="utf-8") as f:
mapping_data = json.load(f)
mapping = mapping_data.get("mapping", {})
probably_mapped_ns = mapping_data.get("probably_mapped_ns", {})
all_mapping = {**mapping, **probably_mapped_ns}
if not all_mapping:
rprint("⚠️ [yellow]No player mappings found. Skipping unified analysis.[/yellow]")
return pd.DataFrame()
# Prepare datasets for merging
df_fpedia_merge = df_fpedia_final.copy()
df_fstats_merge = df_fstats_final.copy()
# Rename columns to avoid conflicts
fpedia_cols = {
col: f"fpedia_{col}"
for col in df_fpedia_merge.columns
if col not in ["Nome", "Ruolo", "Squadra"]
}
fstats_cols = {
col: f"fstats_{col}"
for col in df_fstats_merge.columns
if col not in ["Nome", "Ruolo", "Squadra"]
}
df_fpedia_merge = df_fpedia_merge.rename(columns=fpedia_cols)
df_fstats_merge = df_fstats_merge.rename(columns=fstats_cols)
# Create mapping keys
df_fpedia_merge["mapped_name"] = df_fpedia_merge["Nome"].map(all_mapping)
df_fstats_merge["mapped_name"] = (
df_fstats_merge["fstats_firstname"].fillna("")
+ " "
+ df_fstats_merge["fstats_lastname"].fillna("")
).str.strip()
# Merge
df_merged = pd.merge(
df_fpedia_merge,
df_fstats_merge,
on="mapped_name",
how="inner",
suffixes=("_fpedia", "_fstats"),
)
# Reorder columns
priority_cols = [
"Nome_fpedia",
"mapped_name",
"Ruolo_fpedia",
"Squadra_fpedia",
"fpedia_Convenienza Potenziale",
"fstats_Convenienza Potenziale",
"fpedia_Convenienza",
"fstats_Convenienza",
"fpedia_Punteggio",
"fstats_fantacalcioFantaindex",
"fstats_fanta_avg",
"fstats_presences",
]
remaining_cols = [col for col in df_merged.columns if col not in priority_cols]
final_col_order = [
col for col in priority_cols if col in df_merged.columns
] + remaining_cols
return df_merged[final_col_order]
def _show_top_players(df, source_name, top_n):
"""Helper function to display top players in a nice table"""
if df.empty:
return
rprint(f"\n🏆 [bold]Top {top_n} Players - {source_name}[/bold]")
table = Table(show_header=True, header_style="bold green")
table.add_column("Rank", justify="center", style="bold")
table.add_column("Name", style="cyan")
table.add_column("Role")
table.add_column("Team")
table.add_column("Convenience", justify="right", style="green")
df_top = df.head(top_n)
for idx, (_, row) in enumerate(df_top.iterrows(), 1):
# Handle different column names for unified vs single source datasets
if source_name == "UNIFIED":
convenience = row.get("fpedia_Convenienza Potenziale", row.get("fstats_Convenienza Potenziale", 0))
name = str(row.get("Nome_fpedia", "N/A"))
role = str(row.get("Ruolo_fpedia", "N/A"))
team = str(row.get("Squadra_fpedia", "N/A"))
else:
convenience = row.get("Convenienza Potenziale", row.get("Convenienza", 0))
name = str(row.get("Nome", "N/A"))
role = str(row.get("Ruolo", "N/A"))
team = str(row.get("Squadra", "N/A"))
table.add_row(
str(idx),
name,
role,
team,
f"{convenience:.2f}" if pd.notna(convenience) else "N/A",
)
console.print(table)
if __name__ == "__main__":
# Import pandas here to avoid circular import issues
import pandas as pd
cli()