@@ -145,14 +145,14 @@ async def _initialize_session(self, proxy_url=None):
145
145
self ._session_ready .set ()
146
146
147
147
@classmethod
148
- def _handle_status (cls , status_code ):
148
+ def _handle_status (cls , status_code , fetching_time = 0 ):
149
149
"""Handles error status codes, raising exceptions if necessary."""
150
150
if status_code < 400 :
151
151
return
152
152
if status_code == 403 :
153
- raise Forbidden ("403 Forbidden: Might be getting rate-limited" )
153
+ raise Forbidden ("403 Forbidden: Might be getting rate-limited" , fetching_time = fetching_time )
154
154
else :
155
- raise NetworkError ("Request error, status code: %d" % status_code )
155
+ raise NetworkError ("Request error, status code: %d" % status_code , fetching_time = fetching_time )
156
156
157
157
async def _request (self , method , url , data = None , headers = None ):
158
158
"""Base request, handling possible error statuses.
@@ -182,24 +182,24 @@ async def _request(self, method, url, data=None, headers=None):
182
182
If there's any connection errors during the request.
183
183
"""
184
184
await self ._session_ready .wait ()
185
+ init_time = time .perf_counter ()
185
186
try :
186
- init_time = time .perf_counter ()
187
187
async with self .session .request (method , url , data = data , headers = headers ) as resp :
188
188
diff_time = time .perf_counter ()- init_time
189
189
if "maintenance.tibia.com" in str (resp .url ):
190
190
log .info (f"%s | %s | %s %s | maintenance.tibia.com" , url , resp .method , resp .status , resp .reason )
191
191
raise SiteMaintenanceError ("Tibia.com is down for maintenance." )
192
192
log .info (f"%s | %s | %s %s | %dms" , url , resp .method , resp .status , resp .reason , int (diff_time * 1000 ))
193
- self ._handle_status (resp .status )
193
+ self ._handle_status (resp .status , diff_time )
194
194
response = RawResponse (resp , diff_time )
195
195
response .content = await resp .text ()
196
196
return response
197
197
except aiohttp .ClientError as e :
198
- raise NetworkError ("aiohttp.ClientError: %s" % e , e )
198
+ raise NetworkError ("aiohttp.ClientError: %s" % e , e , time . perf_counter () - init_time )
199
199
except aiohttp_socks .SocksConnectionError as e :
200
- raise NetworkError ("aiohttp_socks.SocksConnectionError: %s" % e , e )
200
+ raise NetworkError ("aiohttp_socks.SocksConnectionError: %s" % e , e , time . perf_counter () - init_time )
201
201
except UnicodeDecodeError as e :
202
- raise NetworkError ('UnicodeDecodeError: %s' % e , e )
202
+ raise NetworkError ('UnicodeDecodeError: %s' % e , e , time . perf_counter () - init_time )
203
203
204
204
async def fetch_current_auctions (self , page = 1 , filters = None ):
205
205
"""Fetches the current auctions in the bazaar
@@ -236,7 +236,7 @@ async def fetch_current_auctions(self, page=1, filters=None):
236
236
parsing_time = time .perf_counter () - start_time
237
237
return TibiaResponse (response , current_auctions , parsing_time )
238
238
239
- async def fetch_auction_history (self , page = 1 ):
239
+ async def fetch_auction_history (self , page = 1 , filters = None ):
240
240
"""Fetches the auction history of the bazaar.
241
241
242
242
.. versionadded:: 3.3.0
@@ -245,6 +245,8 @@ async def fetch_auction_history(self, page=1):
245
245
----------
246
246
page: :class:`int`
247
247
The page to display.
248
+ filters: :class:`AuctionFilters`
249
+ The filtering criteria to use.
248
250
249
251
Returns
250
252
-------
@@ -263,7 +265,7 @@ async def fetch_auction_history(self, page=1):
263
265
"""
264
266
if page <= 0 :
265
267
raise ValueError ('page must be 1 or greater.' )
266
- response = await self ._request ("GET" , CharacterBazaar .get_auctions_history_url (page ))
268
+ response = await self ._request ("GET" , CharacterBazaar .get_auctions_history_url (page , filters ))
267
269
start_time = time .perf_counter ()
268
270
auction_history = CharacterBazaar .from_content (response .content )
269
271
parsing_time = time .perf_counter () - start_time
0 commit comments