22from typing import Any , AsyncGenerator
33
44from bs4 import BeautifulSoup
5- from httpx import AsyncClient
5+ from httpx import AsyncClient , AsyncHTTPTransport , Limits
66
77from .models import IncorrectPassword , SlcmCookies , SlcmCookiesWithName
88
@@ -26,12 +26,21 @@ class SlcmSwitch:
2626 grades_endpoint = "/Student/Academic/GetGradesForFaculty"
2727 internal_marks_endpoint = "/Student/Academic/GetInternalMarkForFaculty"
2828
29+ def __init__ (self ):
30+ self ._transport = AsyncHTTPTransport (
31+ limits = Limits (
32+ max_connections = 50 , max_keepalive_connections = 30 , keepalive_expiry = 300
33+ ),
34+ retries = 2 ,
35+ )
36+
2937 @asynccontextmanager
3038 async def _client (self , * args , ** kwargs ) -> AsyncGenerator [AsyncClient ]:
3139 client = AsyncClient (
3240 base_url = self .base_url ,
3341 headers = {"User-Agent" : self .user_agent },
3442 timeout = 10 ,
43+ transport = self ._transport ,
3544 * args ,
3645 ** kwargs ,
3746 )
@@ -143,19 +152,23 @@ async def parent_resend_otp(self, cookies: SlcmCookies) -> None:
143152 async with self ._client () as client :
144153 # Expire existing OTP
145154 expire_res = await client .post (
146- self .otp_expire_endpoint , data = {"Flag" : "--" }
155+ self .otp_expire_endpoint ,
156+ data = {"Flag" : "--" },
157+ cookies = cookies .model_dump (by_alias = True ),
147158 )
148159 expire_res .raise_for_status ()
149160
150161 # Resend OTP
151162 resend_res = await client .post (
152- self .otp_resend_endpoint , data = {"QnsStr" : "--" }
163+ self .otp_resend_endpoint ,
164+ data = {"QnsStr" : "--" },
165+ cookies = cookies .model_dump (by_alias = True ),
153166 )
154167 resend_res .raise_for_status ()
155168
156169 """Common Endpoints"""
157170
158- async def get_student_info (self , cookies : SlcmCookies ):
171+ async def get_student_info (self , cookies : SlcmCookies ) -> dict :
159172 def extract_value (key : str ) -> str :
160173 input_tag = soup .find ("input" , {"name" : key })
161174 return input_tag ["value" ] if input_tag else "Not found" # type: ignore
0 commit comments