Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 59 additions & 13 deletions integrations/ufc.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,66 @@ def get_event_details(event_url: str) -> dict | None:
location = " ".join(venue_el.get_text().split())
break

# Build description with fight card
# Build description with fight card and broadcast info
description_parts = []

# Main card fights
main_card = soup.select_one("#main-card")
if main_card:
fights = main_card.select(".c-listing-fight")
if fights:
description_parts.append("Main Card:")
for fight in fights[:6]: # Limit to 6 fights
red_corner = fight.select_one(".c-listing-fight__corner--red .c-listing-fight__corner-name")
blue_corner = fight.select_one(".c-listing-fight__corner--blue .c-listing-fight__corner-name")
if red_corner and blue_corner:
description_parts.append(f" {red_corner.get_text(strip=True)} vs {blue_corner.get_text(strip=True)}")
# Find fight card sections (Main Card, Prelims, etc.)
broadcaster_containers = soup.select(".c-event-fight-card-broadcaster__container")

for container in broadcaster_containers:
# Get card title (Main Card, Prelims, etc.)
card_title_el = container.select_one(".c-event-fight-card-broadcaster__card-title strong")
card_title = card_title_el.get_text(strip=True) if card_title_el else "Fight Card"

# Get broadcaster/streaming info
broadcaster_link = container.select_one(".c-event-fight-card-broadcaster__link a")
broadcaster = ""
if broadcaster_link:
broadcaster = broadcaster_link.get_text(strip=True)

# Get the fights for this card section
# The fights follow the broadcaster container in the next <section>
next_section = container.find_next_sibling("section", class_="l-listing--stacked--full-width")
if not next_section:
# Try finding it as next element
next_section = container.find_next("section", class_="l-listing--stacked--full-width")

fights_text = []
if next_section:
fights = next_section.select(".c-listing-fight")
for fight in fights[:5]: # Limit to 5 fights per card
red_name = fight.select_one(".c-listing-fight__corner-name--red")
blue_name = fight.select_one(".c-listing-fight__corner-name--blue")
weight_class = fight.select_one(".c-listing-fight__class-text")

if red_name and blue_name:
# Extract first and last names with proper spacing
red_given = red_name.select_one(".c-listing-fight__corner-given-name")
red_family = red_name.select_one(".c-listing-fight__corner-family-name")
blue_given = blue_name.select_one(".c-listing-fight__corner-given-name")
blue_family = blue_name.select_one(".c-listing-fight__corner-family-name")

if red_given and red_family and blue_given and blue_family:
red = f"{red_given.get_text(strip=True)} {red_family.get_text(strip=True)}"
blue = f"{blue_given.get_text(strip=True)} {blue_family.get_text(strip=True)}"
else:
# Fallback to full text with space separator
red = " ".join(red_name.get_text().split())
blue = " ".join(blue_name.get_text().split())

fight_str = f"• {red} vs {blue}"
if weight_class:
weight = weight_class.get_text(strip=True).replace(" Bout", "")
fight_str += f" ({weight})"
fights_text.append(fight_str)

if fights_text:
header = card_title
if broadcaster:
header += f" - {broadcaster}"
description_parts.append(header)
description_parts.extend(fights_text)
description_parts.append("") # Empty line between sections

# Generate a unique ID from the URL
event_slug = event_url.split("/event/")[-1].split("?")[0]
Expand All @@ -144,7 +190,7 @@ def get_event_details(event_url: str) -> dict | None:
"title": title,
"start": start_time,
"location": location,
"description": "\n".join(description_parts) if description_parts else "",
"description": "\n".join(description_parts).strip() if description_parts else "",
}

except Exception:
Expand Down