حسن سكريبت في ا اوامر الطباعه import requests
import time
from datetime import datetime, timedelta

# قاعدة URL لطلبات API
base_url = "https://www.sofascore.com/api/v1"

# جلب البيانات الحية للأحداث
def get_live_events():
    url = f"{base_url}/sport/football/events/live"
    response = requests.get(url)
    return response.json()

# جلب الأحداث الخاصة بمباراة معينة
def get_event_incidents(event_id):
    url = f"{base_url}/event/{event_id}/incidents"
    response = requests.get(url)
    return response.json()

# تحويل التوقيت إلى توقيت محلي باستخدام المنطقة الزمنية
def convert_to_local_time(utc_timestamp):
    # افترض أن المنطقة الزمنية للجزائر (UTC+1)
    local_time = datetime.utcfromtimestamp(utc_timestamp) + timedelta(hours=1)
    return local_time.strftime('%Y-%m-%d %H:%M:%S')

# عرض البيانات بشكل منظم مع تجنب التكرار
def display_live_data(events, displayed_incidents):
    for event in events.get('events', []):
        tournament = event.get('tournament', {}).get('uniqueTournament', {})
        if tournament.get('name') == "Premier League":
            print(f"Match: {event['homeTeam']['name']} vs {event['awayTeam']['name']}")
            start_timestamp = event.get('startTimestamp', None)
            if start_timestamp:
                start_time = convert_to_local_time(start_timestamp)
            else:
                start_time = 'Unknown Start Time'
            print(f"Start Time: {start_time}")
            incidents = get_event_incidents(event['id'])
            for incident in incidents.get('incidents', []):
                incident_id = incident['id']
                if incident_id not in displayed_incidents:
                    displayed_incidents.add(incident_id)
                    incident_type = incident.get('incidentType', 'Unknown Type')
                    if incident_type == 'goal':
                        player_name = incident.get('player', {}).get('name', 'Unknown Player')
                        time_elapsed = incident.get('time', 0)
                        print(f"Goal! {player_name} at {time_elapsed} minute(s)")
                    elif incident_type == 'card':
                        card_type = incident.get('cardType', 'Unknown Card')
                        player_name = incident.get('player', {}).get('name', 'Unknown Player')
                        print(f"Card! {player_name} received a {card_type} card at {incident['time']} minute(s)")
                    elif incident_type == 'substitution':
                        player_in = incident.get('playerIn', {}).get('name', 'Unknown Player In')
                        player_out = incident.get('playerOut', {}).get('name', 'Unknown Player Out')
                        print(f"Substitution: {player_in} in, {player_out} out at {incident['time']} minute(s)")
                    elif incident_type == 'injuryTime':
                        print(f"Injury Time: {incident['length']} minutes added at {incident['time']} minute(s)")
            print("-" * 30)

# تشغيل السكريبت باستمرار
if __name__ == "__main__":
    displayed_incidents = set()
    try:
        while True:
            live_events = get_live_events()
            display_live_data(live_events, displayed_incidents)
            print("\n--- Fetching updates in 60 seconds ---\n")
            time.sleep(60)  # الانتظار لمدة 60 ثانية قبل تحديث البيانات
    except KeyboardInterrupt:
        print("Script stopped by user.")   الى هكذا نموذج على سبيل المثال  🥅 Goal!    Pedri  55'    
Fc Barcelona 1 -0 Real madrid

🟧 Card    Gavi    67'
⏱️  Halftime   Fc Barcelona 1 -0 Real madrid  
🔁  Sub   Pedri out   Gavi in     99'