Live Cricket Score Alerts with Python

How to Get Live Cricket Score Alerts with Python (Real-Time Notifications)

A Live Cricket Score Alerts project will fetch real-time cricket scores from an API and send alerts using Python. Here’s how you can build it:

Project Overview:

  • Fetch live cricket scores from a sports API.
  • Display scores in terminal or GUI (Tkinter).
  • Send real-time alerts via notifications or email/SMS.

Tools & Libraries:

  • requests → Fetch live data from an API.
  • plyer → Send desktop notifications.
  • schedule → Automate periodic updates.
  • Tkinter (Optional) → Build a GUI.

Step 1: Install Dependencies

pip install requests plyer schedule

Step 2: Get a Live Cricket Score API

Step 3: Fetch Live Cricket Scores

import requests

 

API_KEY = “your_api_key”

MATCH_ID = “your_match_id”  # You need to fetch match ID dynamically

def get_live_score():

    url = f”https://api.cricapi.com/v1/matches?apikey={API_KEY}”

    response = requests.get(url).json()

    for match in response[“data”]:

        if match[“id”] == MATCH_ID:

            return f”{match[‘teams’][0]} vs {match[‘teams’][1]}: {match[‘score’]}”

print(get_live_score())

Step 4: Send Live Score Notifications

from plyer import notification

def send_notification():

    score = get_live_score()

    notification.notify(

        title=”Live Cricket Score”,

        message=score,

        timeout=5

    )

send_notification()

Step 5: Automate Score Updates

import schedule

import time

schedule.every(5).minutes.do(send_notification)

while True:

    schedule.run_pending()

    time.sleep(1)

Bonus: Build a GUI App (Optional)

Use Tkinter to display scores in a small window.

Future Enhancements:

SMS/Email Alerts (Twilio API).
Live Commentary (Sports APIs).
Voice Alerts (Text-to-Speech).

Where I have to insert this code?

You can insert the code in a Python script and run it on your system. Here’s how you should structure your files:

1. Create a Python Script

  • Open a code editor (VS Code, PyCharm, or Notepad++).
  • Create a new file named cricket_score_alert.py.
  • Copy and paste the code inside it.

2. Run the Script

  • Open a terminal or command prompt.
  • Navigate to the folder where your script is saved.
  • Run the script using:
  • python cricket_score_alert.py

3. Automate Alerts (Optional)

  • You can schedule it to run every 5 minutes using schedule.
  • If using Windows, you can add it to the Task Scheduler to run in the background.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *