bep40 commited on
Commit
f6dbdac
·
verified ·
1 Parent(s): ffc9f11

Upload app_main.py

Browse files
Files changed (1) hide show
  1. app_main.py +19 -4
app_main.py CHANGED
@@ -10,7 +10,7 @@ from bs4 import BeautifulSoup
10
  import re, html as html_lib, os, json, threading, time
11
  from concurrent.futures import ThreadPoolExecutor, as_completed
12
 
13
- def _clean(s):return re.sub(r"\s+"," ",html_lib.unescape(str(s or ""))).strip()
14
  _STOP_WORDS=set('và của các những một được trong với cho tại sau trước khi không người việt nam hôm nay mới nhất nóng tin tức cập nhật theo từ đến là có thì'.split())
15
 
16
  def _relevance_score(topic, title):
@@ -40,7 +40,7 @@ def _search_dantri(topic,limit=8):
40
  if t and len(t)>15:
41
  if not href.startswith('http'):href='https://dantri.com.vn'+href
42
  if 'dantri.com.vn' in href:items.append({'title':t,'url':href,'via':'Dân Trí'})
43
- if len(items)>=limit:break
44
  except:pass
45
  return items
46
  def _search_vietnamnet(topic,limit=6):
@@ -52,7 +52,7 @@ def _search_vietnamnet(topic,limit=6):
52
  if t and len(t)>15:
53
  if not href.startswith('http'):href='https://vietnamnet.vn'+href
54
  if 'vietnamnet.vn' in href:items.append({'title':t,'url':href,'via':'VietNamNet'})
55
- if len(items)>=limit:break
56
  except:pass
57
  return items
58
  def _search_all(topic, limit=40):
@@ -124,7 +124,7 @@ def _load_json(path):
124
  def _save_json(path, data):
125
  try:
126
  tmp=path+'.tmp'
127
- with open(tmp,'w',encoding='utf-8') as f:json.dump(data,f,ensure_ascii=False)
128
  os.replace(tmp,path)
129
  except:pass
130
 
@@ -192,6 +192,21 @@ def api_wc2026_lineups(event_id:int):return JSONResponse(scrape_lineups(event_id
192
  @app.get('/api/wc2026/match/{event_id}')
193
  def api_wc2026_match(event_id:int):return JSONResponse(scrape_match_detail(event_id))
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def _wc2026_bg_refresh():
196
  time.sleep(10)
197
  while True:
 
10
  import re, html as html_lib, os, json, threading, time
11
  from concurrent.futures import ThreadPoolExecutor, as_completed
12
 
13
+ def _clean(s):return re.sub(r"\s+"," ",html_lib.unescape(str(s or ""))).stop()
14
  _STOP_WORDS=set('và của các những một được trong với cho tại sau trước khi không người việt nam hôm nay mới nhất nóng tin tức cập nhật theo từ đến là có thì'.split())
15
 
16
  def _relevance_score(topic, title):
 
40
  if t and len(t)>15:
41
  if not href.startswith('http'):href='https://dantri.com.vn'+href
42
  if 'dantri.com.vn' in href:items.append({'title':t,'url':href,'via':'Dân Trí'})
43
+ if len(items)>=limit):break
44
  except:pass
45
  return items
46
  def _search_vietnamnet(topic,limit=6):
 
52
  if t and len(t)>15:
53
  if not href.startswith('http'):href='https://vietnamnet.vn'+href
54
  if 'vietnamnet.vn' in href:items.append({'title':t,'url':href,'via':'VietNamNet'})
55
+ if len(items)>=limit):break
56
  except:pass
57
  return items
58
  def _search_all(topic, limit=40):
 
124
  def _save_json(path, data):
125
  try:
126
  tmp=path+'.tmp'
127
+ with tmp+'.tmp','w',encoding='utf-8') as f:json.dump(data,f,ensure_ascii=False)
128
  os.replace(tmp,path)
129
  except:pass
130
 
 
192
  @app.get('/api/wc2026/match/{event_id}')
193
  def api_wc2026_match(event_id:int):return JSONResponse(scrape_match_detail(event_id))
194
 
195
+ # ============================================================
196
+ # MATCH DETAIL API (for any match from bongda.com.vn)
197
+ # ============================================================
198
+ from match_detail import fetch_match_detail, fetch_match_detail_by_url
199
+
200
+ @app.get('/api/match/{event_id}/detail')
201
+ def api_match_detail(event_id: int):
202
+ """Get complete match detail: preview, lineups, H2H, stats."""
203
+ return JSONResponse(fetch_match_detail(event_id))
204
+
205
+ @app.get('/api/match/detail')
206
+ def api_match_detail_by_url(url: str = Query(...)):
207
+ """Get match detail by full bongda.com.vn URL."""
208
+ return JSONResponse(fetch_match_detail_by_url(url))
209
+
210
  def _wc2026_bg_refresh():
211
  time.sleep(10)
212
  while True: