Mazenbs commited on
Commit
884a60b
·
verified ·
1 Parent(s): 56d507d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -6,7 +6,7 @@ from parser.assembler import parse_law_from_texts
6
  from supabase_utils import save_law_to_supabase
7
  from helpers.indexer import build_indexed_response
8
  from helpers.blocks_all import extract_from_url
9
- from parser.table_extractor import tables_from_soup, table_to_struct
10
 
11
 
12
  app = FastAPI(
@@ -78,26 +78,20 @@ async def extract_link_get(
78
  raise HTTPException(status_code=500, detail=f"خطأ في معالجة المحتوى: {str(e)}")
79
 
80
 
 
81
  @app.get("/extract_tables")
82
  async def extract_tables_get(
83
  url: HttpUrl = Query(..., description="رابط الصفحة المراد استخراج الجداول منها"),
84
  timeout: int = Query(10, ge=1, le=60, description="مهلة الطلب بالثواني")
85
  ):
86
  """
87
- استخراج جميع الجداول من صفحة الويب وإرجاعها كهيكل JSON مرتب.
88
  """
89
  try:
90
- # 1) جلب محتوى الصفحة
91
- html_content = await extract_from_url(str(url), timeout)
92
-
93
- # 2) تحويل HTML إلى BeautifulSoup
94
- soup = BeautifulSoup(html_content, "html.parser")
95
-
96
- # 3) استخراج كل الجداول
97
- tables = tables_from_soup(soup)
98
- structured_tables = [table_to_struct(table) for table in tables]
99
-
100
- return {"count": len(structured_tables), "tables": structured_tables}
101
 
102
  except Exception as e:
103
- raise HTTPException(status_code=500, detail=f"خطأ في معالجة الجداول: {str(e)}")
 
 
6
  from supabase_utils import save_law_to_supabase
7
  from helpers.indexer import build_indexed_response
8
  from helpers.blocks_all import extract_from_url
9
+ from parser.extract_tables_by_article import extract_tables_from_url
10
 
11
 
12
  app = FastAPI(
 
78
  raise HTTPException(status_code=500, detail=f"خطأ في معالجة المحتوى: {str(e)}")
79
 
80
 
81
+
82
  @app.get("/extract_tables")
83
  async def extract_tables_get(
84
  url: HttpUrl = Query(..., description="رابط الصفحة المراد استخراج الجداول منها"),
85
  timeout: int = Query(10, ge=1, le=60, description="مهلة الطلب بالثواني")
86
  ):
87
  """
88
+ استخراج جميع الجداول المرتبطة بالمواد من صفحة الويب وإرجاعها كهيكل JSON مرتب.
89
  """
90
  try:
91
+ # استخدام الوظيفة المستقلة الجديدة
92
+ result = await extract_tables_from_url(str(url), timeout)
93
+ return result
 
 
 
 
 
 
 
 
94
 
95
  except Exception as e:
96
+ raise HTTPException(status_code=500, detail=f"خطأ في معالجة الجداول: {str(e)}")
97
+