from flask import Flask, Response import requests from datetime import datetime import pytz app = Flask(__name__) @app.route('/matches') def get_matches(): try: # تظبيط الوقت على توقيت مصر cairo_tz = pytz.timezone('Africa/Cairo') today_date = datetime.now(cairo_tz).strftime('%Y-%m-%d') # رابط API في الجول المباشر url = f"https://api.filgoal.com/api/home/GetMatches?date={today_date}" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': 'application/json' } response = requests.get(url, headers=headers, timeout=10) matches_data = response.json() target_match = None # البحث عن أول مباراة مهمة (لم تبدأ أو تلعب الآن) for championship in matches_data: for match in championship.get('matches', []): status_id = match.get('matchStatusId') # 1 = لم تبدأ، 2 = مباشر if status_id in [1, 2]: target_match = match break if target_match: break if not target_match: return Response("NoMatches", mimetype='text/plain;charset=UTF-8') # استخراج أسماء الفرق، الميعاد، والقناة team_a = target_match.get('homeTeamName', 'فريق 1') team_b = target_match.get('awayTeamName', 'فريق 2') match_time_raw = target_match.get('date', '') # تظبيط شكل الساعة if 'T' in match_time_raw: match_time = match_time_raw.split('T')[1][:5] else: match_time = "قريباً" channel = target_match.get('tvChannelName', 'غير محدد') if not channel: channel = "غير محدد" # تجميع الرسالة النهائية text = f"مباراة {team_a} ضد {team_b} الساعة {match_time} على {channel}" return Response(text, mimetype='text/plain;charset=UTF-8') except Exception as e: return Response("NoMatches", mimetype='text/plain;charset=UTF-8') @app.route('/') def home(): return "Shalaby Match Notifier API is Running!" if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)