bep40 commited on
Commit
38ce433
·
verified ·
1 Parent(s): d8a19ed

Restore e80f9c8: match_detail_v2.py

Browse files
Files changed (1) hide show
  1. match_detail_v2.py +1 -47
match_detail_v2.py CHANGED
@@ -133,39 +133,6 @@ def parse_events(sp):
133
  return events
134
 
135
 
136
- def _get_slug_from_api(event_id: int) -> str:
137
- """Fetch match slug from bongda API to build full URL."""
138
- endpoints = [
139
- f"/api/fixtures/live",
140
- f"/api/fixtures/get-by-date?date=__today__",
141
- f"/api/fixtures/incoming",
142
- ]
143
- import datetime
144
- today = datetime.date.today().strftime("%Y-%m-%d")
145
- for ep in endpoints:
146
- ep = ep.replace("__today__", today)
147
- try:
148
- resp = requests.get(
149
- f"https://bongda.com.vn{ep}",
150
- headers=API_HEADERS, timeout=6
151
- )
152
- if resp.status_code == 200:
153
- data = resp.json()
154
- html = data.get("html", "")
155
- if html:
156
- sp = _mk(html)
157
- for li in sp.select("li.match-detail"):
158
- status_a = li.select_one(".status a")
159
- if status_a:
160
- href = status_a.get("href", "")
161
- m = re.search(r'/tran-dau/(\d+)/', href)
162
- if m and int(m.group(1)) == event_id:
163
- return href # e.g. /tran-dau/123/preview/slug-name
164
- except Exception:
165
- continue
166
- return ""
167
-
168
-
169
  def fetch_match_detail(event_id: int) -> dict:
170
  import concurrent.futures
171
  result = {"event_id": event_id, "found": False, "sections": []}
@@ -188,20 +155,6 @@ def fetch_match_detail(event_id: int) -> dict:
188
  except Exception:
189
  continue
190
 
191
- # If no slug URL worked, try to get slug from API
192
- if not html:
193
- slug_path = _get_slug_from_api(event_id)
194
- if slug_path:
195
- try:
196
- resp = requests.get(
197
- f"https://bongda.com.vn{slug_path}",
198
- headers=HEADERS, timeout=10, allow_redirects=True
199
- )
200
- if resp.status_code == 200 and len(resp.text) > 1000:
201
- html = resp.text
202
- except Exception:
203
- pass
204
-
205
  if not html:
206
  return result
207
 
@@ -331,6 +284,7 @@ def fetch_match_detail(event_id: int) -> dict:
331
 
332
 
333
  def fetch_match_detail_by_url(url: str) -> dict:
 
334
  eid_match = re.search(r'/tran-dau/(\d+)/', url)
335
  if not eid_match:
336
  return {"event_id": 0, "found": False, "error": "Cannot extract event_id from URL"}
 
133
  return events
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  def fetch_match_detail(event_id: int) -> dict:
137
  import concurrent.futures
138
  result = {"event_id": event_id, "found": False, "sections": []}
 
155
  except Exception:
156
  continue
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  if not html:
159
  return result
160
 
 
284
 
285
 
286
  def fetch_match_detail_by_url(url: str) -> dict:
287
+ import concurrent.futures
288
  eid_match = re.search(r'/tran-dau/(\d+)/', url)
289
  if not eid_match:
290
  return {"event_id": 0, "found": False, "error": "Cannot extract event_id from URL"}