Update app.py
Browse files
app.py
CHANGED
|
@@ -20,10 +20,11 @@ import uvicorn
|
|
| 20 |
import random
|
| 21 |
import docx # لإضافة دعم .docx
|
| 22 |
|
| 23 |
-
# ========== (الحل) إضافة المكتبات الصحيحة لحل مشكلة DNS ==========
|
| 24 |
import httpx
|
| 25 |
import dns.asyncresolver
|
| 26 |
from httpx import AsyncClient, AsyncHTTPTransport, Request, Response
|
|
|
|
| 27 |
# ==========================================================
|
| 28 |
|
| 29 |
# ========== تكوين السجلات ==========
|
|
@@ -96,7 +97,9 @@ class CustomDNSTransport(AsyncHTTPTransport):
|
|
| 96 |
|
| 97 |
|
| 98 |
# ========== تطبيق FastAPI ==========
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
async def lifespan(app: FastAPI):
|
| 101 |
logger.info("🚀 بدء تشغيل FastAPI... بدء مهمة تهيئة البوت في الخلفية.")
|
| 102 |
asyncio.create_task(bot.initialize_application())
|
|
@@ -105,6 +108,8 @@ async def lifespan(app: FastAPI):
|
|
| 105 |
logger.info("🛑 إيقاف تشغيل خادم FastAPI.")
|
| 106 |
|
| 107 |
app = FastAPI(title="Medical Lab Bot", version="1.0.0", lifespan=lifespan)
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# ========== فئة البوت الرئيسية ==========
|
| 110 |
class MedicalLabBot:
|
|
@@ -125,7 +130,7 @@ class MedicalLabBot:
|
|
| 125 |
|
| 126 |
logger.info("🔄 جاري تهيئة تطبيق التليجرام...")
|
| 127 |
|
| 128 |
-
# ==========
|
| 129 |
logger.info("🔧 إعداد عميل HTTP مخصص مع CustomDNSTransport...")
|
| 130 |
custom_transport = CustomDNSTransport()
|
| 131 |
custom_client = httpx.AsyncClient(transport=custom_transport)
|
|
|
|
| 20 |
import random
|
| 21 |
import docx # لإضافة دعم .docx
|
| 22 |
|
| 23 |
+
# ========== (الحل) إضافة المكتبات الصحيحة لحل مشكلة DNS + Lifespan ==========
|
| 24 |
import httpx
|
| 25 |
import dns.asyncresolver
|
| 26 |
from httpx import AsyncClient, AsyncHTTPTransport, Request, Response
|
| 27 |
+
import contextlib # <-- إضافة المكتبة الصحيحة
|
| 28 |
# ==========================================================
|
| 29 |
|
| 30 |
# ========== تكوين السجلات ==========
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
# ========== تطبيق FastAPI ==========
|
| 100 |
+
# ========== !! الحــل !! ==========
|
| 101 |
+
# تم تغيير @asyncio.contextmanager إلى @contextlib.asynccontextmanager
|
| 102 |
+
@contextlib.asynccontextmanager
|
| 103 |
async def lifespan(app: FastAPI):
|
| 104 |
logger.info("🚀 بدء تشغيل FastAPI... بدء مهمة تهيئة البوت في الخلفية.")
|
| 105 |
asyncio.create_task(bot.initialize_application())
|
|
|
|
| 108 |
logger.info("🛑 إيقاف تشغيل خادم FastAPI.")
|
| 109 |
|
| 110 |
app = FastAPI(title="Medical Lab Bot", version="1.0.0", lifespan=lifespan)
|
| 111 |
+
# =================================
|
| 112 |
+
|
| 113 |
|
| 114 |
# ========== فئة البوت الرئيسية ==========
|
| 115 |
class MedicalLabBot:
|
|
|
|
| 130 |
|
| 131 |
logger.info("🔄 جاري تهيئة تطبيق التليجرام...")
|
| 132 |
|
| 133 |
+
# ========== الحل الجذري (DNS) ==========
|
| 134 |
logger.info("🔧 إعداد عميل HTTP مخصص مع CustomDNSTransport...")
|
| 135 |
custom_transport = CustomDNSTransport()
|
| 136 |
custom_client = httpx.AsyncClient(transport=custom_transport)
|