Batnini commited on
Commit
0b9d33f
·
verified ·
1 Parent(s): 852d7f8

Update tools/quran_search.py

Browse files
Files changed (1) hide show
  1. tools/quran_search.py +16 -11
tools/quran_search.py CHANGED
@@ -1,25 +1,30 @@
1
  import requests
 
2
 
3
- class QuranFetcher:
4
- BASE_URL = "https://api.quran.com/api/v3"
5
-
 
 
6
  def get_all_surahs(self):
7
- """Get only surah list - nothing more"""
8
  try:
9
- response = requests.get(f"{self.BASE_URL}/chapters", timeout=5)
10
  return response.json().get('chapters', [])
11
- except:
 
12
  return []
13
 
14
- def get_surah_text(self, surah_id):
15
- """Get pure Arabic text for one surah - nothing more"""
16
  try:
17
  response = requests.get(
18
- f"{self.BASE_URL}/chapters/{surah_id}/verses",
19
  params={"language": "ar"},
20
- timeout=10
21
  )
22
  verses = response.json().get('verses', [])
23
  return "\n".join([v['text_uthmani'] for v in verses])
24
- except:
 
25
  return "⚠️ تعذر تحميل السورة"
 
1
  import requests
2
+ import logging
3
 
4
+ class QuranSearchEngine:
5
+ def __init__(self):
6
+ self.api_url = "https://api.quran.com/api/v3"
7
+ logging.basicConfig(level=logging.INFO)
8
+
9
  def get_all_surahs(self):
10
+ """Fetch list of all 114 surahs"""
11
  try:
12
+ response = requests.get(f"{self.api_url}/chapters", timeout=10)
13
  return response.json().get('chapters', [])
14
+ except Exception as e:
15
+ logging.error(f"Surah list error: {str(e)}")
16
  return []
17
 
18
+ def get_full_surah(self, surah_id):
19
+ """Fetch complete surah text"""
20
  try:
21
  response = requests.get(
22
+ f"{self.api_url}/chapters/{surah_id}/verses",
23
  params={"language": "ar"},
24
+ timeout=15
25
  )
26
  verses = response.json().get('verses', [])
27
  return "\n".join([v['text_uthmani'] for v in verses])
28
+ except Exception as e:
29
+ logging.error(f"Surah fetch error: {str(e)}")
30
  return "⚠️ تعذر تحميل السورة"