File size: 1,600 Bytes
63a866c
6ee808a
6241232
 
6ee808a
6241232
6ee808a
63a866c
6ee808a
 
63a866c
6ee808a
63a866c
6241232
6ee808a
63a866c
 
46d07ee
63a866c
6ee808a
 
63a866c
43cbd69
6ee808a
 
 
 
 
b522997
6ee808a
6241232
 
6149a3d
63a866c
 
6ee808a
 
 
 
6149a3d
 
 
 
 
 
 
6ee808a
 
 
 
 
 
 
 
443726d
6ee808a
6241232
6ee808a
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
# openboxing_api.py
# openboxing_api.py
import requests

BASE_URL = "https://openboxing.org/api"

def get_all_champions():
    """
    Fetch all champions/fighters from Open Boxing API.
    Returns a list of fighter dictionaries.
    """
    url = f"{BASE_URL}/champions/all.json"
    response = requests.get(url)
    if response.status_code == 200:
        return response.json()
    return []

def find_champion_by_name(all_champs, name: str):
    """
    Search for a fighter/champion by name.
    Returns the first match dict or None if not found.
    """
    name_lower = name.lower().strip()
    for champ in all_champs:
        first = champ['name'].get('first', '').lower()
        last = champ['name'].get('last', '').lower()
        full_name = f"{first} {last}".strip()
        if name_lower in full_name:
            print(champ)
            return champ
    return None

def get_all_bouts():
    url = f"{BASE_URL}/bouts/all.json"
    response = requests.get(url)
    if response.status_code != 200:
        return []

    bouts = response.json()
    return bouts

def get_bouts_for_champion(bouts, champion_id: int):
    """
    Fetch all bouts/fights for a given champion ID.
    Returns a list of bout dictionaries.
    """
    champ_bouts = []

    for bout in bouts:
        boxers = bout.get("boxers", {})
        boxerA = boxers.get("boxerA", {})
        boxerB = boxers.get("boxerB", {})

        if boxerA.get("championId") == champion_id or boxerB.get("championId") == champion_id:
            print(boxerA, boxerB)
            champ_bouts.append(bout)

    return champ_bouts