Spaces:
Sleeping
Sleeping
File size: 5,140 Bytes
a1d6a25 df042c2 a1d6a25 403995d a1d6a25 9ec1197 329c48a 3058e20 231b31b bc8aa30 c3a0d64 bc8aa30 df042c2 42d29ab 329c48a 9ec1197 df042c2 329c48a df042c2 3058e20 9ec1197 df042c2 9ec1197 329c48a 9ec1197 329c48a 9ec1197 df042c2 329c48a 9ec1197 329c48a df042c2 0970329 329c48a 9ec1197 329c48a 9ec1197 329c48a 9ec1197 329c48a 9ec1197 329c48a 9ec1197 329c48a 9ec1197 329c48a 9ec1197 df042c2 9ec1197 231b31b | 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 | import streamlit as st
from streamlit_autorefresh import st_autorefresh
import requests
from bs4 import BeautifulSoup
from datetime import datetime
st.set_page_config(page_title="IPL Score Stream", layout="centered")
st_autorefresh(interval=5000, limit=None, key="ipl_autorefresh")
st.markdown(f"""
<h1 style='text-align: center;'>π IPL Score Stream</h1>
<p style='text-align: center; font-size: 16px; color: gray;'>
β±οΈ Last updated: {datetime.now().strftime('%H:%M:%S')}
</p>
""", unsafe_allow_html=True)
CURRENT_YEAR = datetime.now().year
YEAR_CODE_MAPPING = {2025: "9237"}
YEAR_CODE = YEAR_CODE_MAPPING.get(CURRENT_YEAR, "default_code")
BASE_URL = "https://www.cricbuzz.com"
IPL_SERIES_URL = f"{BASE_URL}/cricket-series/{YEAR_CODE}/indian-premier-league-{CURRENT_YEAR}"
IPL_MATCHES_URL = f"{IPL_SERIES_URL}/matches"
LIVE_KEYWORDS = ["won the toss", "opt", "elect", "need", "needs", "chose to", "innings", "innings Break", "strategic timeout"]
def fetch_live_ipl_matches():
url = f"{BASE_URL}/cricket-match/live-scores"
headers = {"User-Agent": "Mozilla/5.0"}
soup = BeautifulSoup(requests.get(url, headers=headers).text, "html.parser")
live_matches = []
sections = soup.find_all("div", class_="cb-col cb-col-100 cb-plyr-tbody cb-rank-hdr cb-lv-main")
for section in sections:
header = section.find("h2", class_="cb-lv-grn-strip")
if not header or not header.find("span", class_="cb-plus-ico cb-ico-live-stream"):
continue
match_blocks = section.find_all("div", class_="cb-mtch-lst")
for block in match_blocks:
title_tag = block.find("h3", class_="cb-lv-scr-mtch-hdr")
match_title = title_tag.get_text(strip=True).rstrip(',') if title_tag else "N/A"
team1 = block.find("div", class_="cb-hmscg-bwl-txt")
score1 = team1.find_all("div", class_="cb-ovr-flo")[1].text.strip() if team1 else "N/A"
team2 = block.find("div", class_="cb-hmscg-bat-txt")
score2 = team2.find_all("div", class_="cb-ovr-flo")[1].text.strip() if team2 else "N/A"
status_tag = block.find("div", class_="cb-text-live")
status = status_tag.text.strip() if status_tag else ""
if any(k in status.lower() for k in LIVE_KEYWORDS):
live_matches.append({
"Match Title": match_title,
"Batting Score": score2,
"Bowling Score": score1,
"Status": status
})
return live_matches
def get_recent_news():
headers = {"User-Agent": "Mozilla/5.0"}
soup = BeautifulSoup(requests.get(IPL_SERIES_URL, headers=headers).text, "html.parser")
tags = soup.find_all("a", class_="cb-nws-hdln-ancr")
return [(tag.text.strip(), BASE_URL + tag["href"]) for tag in tags[:10]]
def get_recent_match_results():
headers = {"User-Agent": "Mozilla/5.0"}
soup = BeautifulSoup(requests.get(IPL_MATCHES_URL, headers=headers).text, "html.parser")
result_blocks = soup.find_all("a", href=True)
results = []
for tag in result_blocks:
if "won by" in tag.text.lower():
desc = tag.text.strip()
link = BASE_URL + tag["href"]
parent = tag.find_parent("div", class_="cb-col-100 cb-col")
date_tag = parent.find("div", class_="schedule-date") if parent else None
date = date_tag.text.strip() if date_tag else "β"
results.append((date, desc, link))
return results[-5:][::-1] if results else []
def get_upcoming_matches():
headers = {"User-Agent": "Mozilla/5.0"}
soup = BeautifulSoup(requests.get(IPL_MATCHES_URL, headers=headers).text, "html.parser")
matches = []
for block in soup.select("div.cb-series-matches"):
title_tag = block.select_one("a.text-hvr-underline")
venue_tag = block.select_one("div.text-gray")
time_tag = block.select_one("a.cb-text-upcoming")
if title_tag and venue_tag and time_tag:
title = title_tag.text.strip()
venue = venue_tag.text.strip()
start = time_tag.text.strip()
link = BASE_URL + title_tag["href"]
matches.append(f"- [{title} at {venue}]({link})")
return matches[:5]
st.subheader("π’ Live Matches")
matches = fetch_live_ipl_matches()
if matches:
for match in matches:
st.markdown(f"#### π₯ {match['Match Title']}")
st.markdown(f"π **Batting Side**: {match['Batting Score']}")
st.markdown(f"π― **Bowling Side**: {match['Bowling Score']}")
st.markdown(f"π£ **Status**: {match['Status']}")
st.markdown("---")
else:
st.warning("β No live IPL matches currently.")
st.markdown("---")
st.subheader("π
Recent Match Results")
for _, desc, link in get_recent_match_results():
st.markdown(f"- [{desc}]({link})")
st.divider()
st.subheader("ποΈ Upcoming Matches")
for line in get_upcoming_matches():
st.markdown(line)
st.divider()
st.subheader("π° Latest IPL News")
for title, link in get_recent_news():
st.markdown(f"- [{title}]({link})") |