diff --git a/utils_v2/nse/controllers/ipo/current.py b/utils_v2/nse/controllers/ipo/current.py index 346532a..641c8d2 100644 --- a/utils_v2/nse/controllers/ipo/current.py +++ b/utils_v2/nse/controllers/ipo/current.py @@ -105,7 +105,7 @@ class NSECurrentIPO(AsyncNSEBase): # Pass on the initialization to the parent: super().__init__( - base_url = r"https://www.nseindia.com/market-data/all-upcoming-issues-ipo", + base_url = r"https://www.nseindia.com/", data_url = r"https://www.nseindia.com/api/ipo-current-issue", http_client = http_client, cookies_refresh_interval = cookies_refresh_interval, diff --git a/utils_v2/nse/controllers/ipo/upcoming.py b/utils_v2/nse/controllers/ipo/upcoming.py index e791e62..b63b75c 100644 --- a/utils_v2/nse/controllers/ipo/upcoming.py +++ b/utils_v2/nse/controllers/ipo/upcoming.py @@ -106,7 +106,7 @@ class NSEUpcomingIPO(AsyncNSEBase): # Pass on the initialization to the parent: super().__init__( - base_url = r"https://www.nseindia.com/market-data/all-upcoming-issues-ipo", + base_url = r"https://www.nseindia.com/", data_url = r"https://www.nseindia.com/api/all-upcoming-issues?category=ipo", http_client = http_client, cookies_refresh_interval = cookies_refresh_interval, @@ -218,7 +218,7 @@ class NSEUpcomingIPO(AsyncNSEBase): formatted_data = [] for ipo in raw_json: issue_size = regex.find_first(text = str(ipo.get("issueSize")), pattern = r"[\d,]+\.?[\d,]*") - upper_band, lower_band = self.get_band_prices(ipo.get("priceRange")) + upper_band, lower_band = self.get_band_prices(ipo.get("issuePrice")) formatted_data.append(NSEIPO( scrapeTs = timestamp, symbol = ipo["symbol"], diff --git a/utils_v2/rest/controllers/async_base.py b/utils_v2/rest/controllers/async_base.py index a5704be..5304961 100644 --- a/utils_v2/rest/controllers/async_base.py +++ b/utils_v2/rest/controllers/async_base.py @@ -190,6 +190,9 @@ class AsyncREST: api_response.httpCode = response.status_code api_response.message = response.reason_phrase + # Assume success if the response's HTTP code is in the 200 series: + api_response.success = response.is_success + # If something goes wrong: except Exception as exception: api_response.exception = exception @@ -244,6 +247,9 @@ class AsyncREST: api_response.httpCode = response.status_code api_response.message = response.reason_phrase + # Assume success if the response's HTTP code is in the 200 series: + api_response.success = response.is_success + # If something goes wrong: except Exception as exception: api_response.exception = exception @@ -295,6 +301,66 @@ class AsyncREST: api_response.httpCode = response.status_code api_response.message = response.reason_phrase + # Assume success if the response's HTTP code is in the 200 series: + api_response.success = response.is_success + + # If something goes wrong: + except Exception as exception: + api_response.exception = exception + api_response.message = str(exception) + self._printer(exception, api_response.url, api_response.method, headers, json, data) + + # Done here: + return api_response + + async def patch( + self, + url: str, + headers: dict = None, + json: dict = None, + data: dict = None, + content: str | bytes = None, + auth: httpx.Auth = None + ) -> ApiResponse: + + """ + To call an API using the PATCH method. + :param url: The URL to call. + :param headers: The headers to pass. + :param json: The params to send in the JSON body. + :param data: The params to send in the form-data in the body. + :param content: The raw content to be sent in the body (typically as an octet-stream). + :param auth: Any authentication credentials that need to be sent. + :return: A structured response that includes the raw response, the exception (if any), and so on. + """ + + # Prepare the structure of the response: + api_response = ApiResponse( + action = inspect.stack()[1].function, + url = url, + method = "POST" + ) + + try: + + # Make the API call: + response = await self._http_client.patch( + url = url, + headers = headers, + json = json, + data = data, + content = content, + auth = auth + ) + + # Note down the results: + api_response.response = response + api_response.httpCode = response.status_code + api_response.message = response.reason_phrase + + # Assume success if the response's HTTP code is in the 200 series: + api_response.success = response.is_success + # If something goes wrong: except Exception as exception: api_response.exception = exception @@ -340,6 +406,9 @@ class AsyncREST: api_response.httpCode = response.status_code api_response.message = response.reason_phrase + # Assume success if the response's HTTP code is in the 200 series: + api_response.success = response.is_success + # If something goes wrong: except Exception as exception: api_response.exception = exception