Mazenbs commited on
Commit
6e6e56f
·
verified ·
1 Parent(s): 1ad4690

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -6,6 +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
 
10
 
11
  app = FastAPI(
@@ -74,4 +75,29 @@ async def extract_link_get(
74
  return raw_texts
75
 
76
  except Exception as e:
77
- 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.table_extractor import tables_from_soup, table_to_struct
10
 
11
 
12
  app = FastAPI(
 
75
  return raw_texts
76
 
77
  except Exception as e:
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)}")