-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
109 lines (92 loc) · 3.62 KB
/
Copy pathdemo.py
File metadata and controls
109 lines (92 loc) · 3.62 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
"""
demo.py — Quick command-line demo for the Ballon d'Or Scraper.
Runs all four modes (None, Player, Nation, Club) with a default
configuration and prints results to the console.
Usage
-----
python demo.py
python demo.py --player "Cristiano Ronaldo" --start 2000 --end 2023
python demo.py --player "Ronaldo" --start 1995 --end 2005 --viz Club
Requirements
------------
pip install -r requirements.txt
"""
import argparse
import sys
# ── Attempt import ────────────────────────────────────────────────────────────
try:
from ballon_dor_scraper import ballon_dor_scraper
except ImportError:
# Fallback: load the function directly from the notebook source
import importlib.util, types, json, textwrap
with open("ballon_dor_scraper.ipynb", "r", encoding="utf-8") as f:
nb = json.load(f)
source_cells = [
"".join(cell["source"])
for cell in nb["cells"]
if cell["cell_type"] == "code"
]
# Only the first code cell contains the function definitions
module_source = source_cells[0] if source_cells else ""
mod = types.ModuleType("ballon_dor_scraper")
exec(compile(module_source, "ballon_dor_scraper.ipynb", "exec"), mod.__dict__)
ballon_dor_scraper = mod.ballon_dor_scraper
# ── CLI argument parsing ──────────────────────────────────────────────────────
def parse_args():
parser = argparse.ArgumentParser(
description="Ballon d'Or Scraper — command-line demo",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=textwrap.dedent("""
Examples:
python demo.py
python demo.py --player "Cristiano Ronaldo" --start 2010 --end 2023
python demo.py --viz Nation
python demo.py --viz Club --start 1990 --end 2010
""")
)
parser.add_argument(
"--url",
default="https://en.wikipedia.org/wiki/Ballon_d%27Or",
help="Wikipedia Ballon d'Or page URL (default: Wikipedia EN)"
)
parser.add_argument(
"--start", type=int, default=2000,
help="Start year, inclusive (default: 2000)"
)
parser.add_argument(
"--end", type=int, default=2023,
help="End year, inclusive (default: 2023)"
)
parser.add_argument(
"--player", default="Lionel Messi",
help="Player name to query (default: 'Lionel Messi')"
)
parser.add_argument(
"--viz", default="None",
choices=["None", "Player", "Nation", "Club"],
help="Visualisation mode (default: None)"
)
return parser.parse_args()
# ── Main ──────────────────────────────────────────────────────────────────────
def main():
args = parse_args()
print("=" * 60)
print(" Ballon d'Or Scraper & Analyser")
print("=" * 60)
print(f" Year range : {args.start} – {args.end}")
print(f" Query : {args.player}")
print(f" Viz mode : {args.viz}")
print("=" * 60)
print()
df = ballon_dor_scraper(
url=args.url,
start=args.start,
end=args.end,
PerfQuery=args.player,
viz=args.viz
)
print(f"\nDataFrame shape : {df.shape[0]} rows × {df.shape[1]} columns")
print("\nFirst 10 rows:")
print(df.head(10).to_string(index=False))
if __name__ == "__main__":
main()