Spaces:
Sleeping
Sleeping
Create init_db.py
Browse files- init_db.py +32 -0
init_db.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
from crawler import fetch_news_from_aljazeera
|
| 3 |
+
from indexer import create_database, save_news_to_db
|
| 4 |
+
|
| 5 |
+
def initialize():
|
| 6 |
+
print("🔄 جاري تهيئة قاعدة البيانات...")
|
| 7 |
+
create_database()
|
| 8 |
+
|
| 9 |
+
print("🔄 جلب آخر الأخبار...")
|
| 10 |
+
news_list = fetch_news_from_aljazeera()
|
| 11 |
+
|
| 12 |
+
if news_list:
|
| 13 |
+
save_news_to_db(news_list)
|
| 14 |
+
print(f"✅ تم حفظ {len(news_list)} خبر")
|
| 15 |
+
else:
|
| 16 |
+
# أخبار وهمية للتجربة إذا فشل الجلب
|
| 17 |
+
sample_news = [
|
| 18 |
+
{
|
| 19 |
+
'title': 'مثال: تقنية جديدة في مجال الذكاء الاصطناعي',
|
| 20 |
+
'link': 'https://example.com/news1',
|
| 21 |
+
'summary': 'هذا مثال على خبر تجريبي لاختبار محرك البحث',
|
| 22 |
+
'source': 'مصدر تجريبي',
|
| 23 |
+
'date': '2024-01-01 12:00:00'
|
| 24 |
+
}
|
| 25 |
+
]
|
| 26 |
+
save_news_to_db(sample_news)
|
| 27 |
+
print("⚠️ تم حفظ أخبار تجريبية بدلاً من ذلك")
|
| 28 |
+
|
| 29 |
+
print("✅ اكتمل التهيئة!")
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
initialize()
|