bep40 commited on
Commit
fa0e8d3
·
verified ·
1 Parent(s): fa01fdf

Upload main.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. main.py +18 -5
main.py CHANGED
@@ -4,7 +4,7 @@ import html as html_lib
4
  from datetime import datetime
5
  from concurrent.futures import ThreadPoolExecutor, as_completed
6
  from fastapi import FastAPI, Query, Request
7
- from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse, Response, RedirectResponse
8
  from fastapi.staticfiles import StaticFiles
9
  from urllib.parse import unquote, quote, urlencode
10
  import requests
@@ -334,8 +334,22 @@ def api_livescore_featured():
334
  for match in all_matches:
335
  if pl in match["league"]:return match
336
  return all_matches[0]
 
 
 
 
 
 
 
 
 
 
 
337
  return None
338
- return JSONResponse(_cached("ls_featured",_f,ttl=30))
 
 
 
339
 
340
  # ===== VIDEO APIs =====
341
  @app.get("/api/shorts")
@@ -944,9 +958,8 @@ async def video_share(url:str=Query(default=""),title:str=Query(default="VNEWS V
944
  @app.get("/s")
945
  async def share_redirect(url:str=Query(default=""),title:str=Query(default="VNEWS"),img:str=Query(default="")):
946
  decoded_url=unquote(url)
947
- if decoded_url and decoded_url.startswith("http"):
948
- return RedirectResponse(url=decoded_url, status_code=302)
949
- return RedirectResponse(url=SPACE_URL, status_code=302)
950
  @app.get("/")
951
  async def index():
952
  with open("/app/static/index.html","r",encoding="utf-8") as f:return HTMLResponse(content=f.read())
 
4
  from datetime import datetime
5
  from concurrent.futures import ThreadPoolExecutor, as_completed
6
  from fastapi import FastAPI, Query, Request
7
+ from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse, Response
8
  from fastapi.staticfiles import StaticFiles
9
  from urllib.parse import unquote, quote, urlencode
10
  import requests
 
334
  for match in all_matches:
335
  if pl in match["league"]:return match
336
  return all_matches[0]
337
+ # Fallback: scrape bongda.com.vn homepage HTML directly
338
+ try:
339
+ r = requests.get("https://bongda.com.vn/", headers={"User-Agent": "Mozilla/5.0"}, timeout=10)
340
+ if r.status_code == 200:
341
+ soup = BeautifulSoup(r.text, "lxml")
342
+ for li in soup.select("li.match-detail"):
343
+ match = _parse_match_from_li(li, "today")
344
+ if match and match.get("event_id"):
345
+ return match
346
+ except:
347
+ pass
348
  return None
349
+ result = _f()
350
+ if result:
351
+ return JSONResponse(result)
352
+ return JSONResponse({"home": "", "away": "", "score": "VS", "league": "", "event_id": "", "url": "", "status": "no_match"})
353
 
354
  # ===== VIDEO APIs =====
355
  @app.get("/api/shorts")
 
958
  @app.get("/s")
959
  async def share_redirect(url:str=Query(default=""),title:str=Query(default="VNEWS"),img:str=Query(default="")):
960
  decoded_url=unquote(url)
961
+ redirect_script=f'<script>localStorage.setItem("pending_article","{decoded_url}");location.href="{SPACE_URL}";</script>' if decoded_url else f'<script>location.href="{SPACE_URL}";</script>'
962
+ return HTMLResponse(f'<!DOCTYPE html><html><head><meta charset="utf-8"><title>{unquote(title)}</title></head><body>{redirect_script}</body></html>')
 
963
  @app.get("/")
964
  async def index():
965
  with open("/app/static/index.html","r",encoding="utf-8") as f:return HTMLResponse(content=f.read())