diff --git a/newsdataapi/constants.py b/newsdataapi/constants.py index 9f718d6..8c67c5a 100644 --- a/newsdataapi/constants.py +++ b/newsdataapi/constants.py @@ -15,6 +15,8 @@ COUNT_ENDPOINT = 'count' +CRYPTO_COUNT_ENDPOINT = 'crypto/count' + # Default request values DEFAULT_REQUEST_TIMEOUT = 300 DEFAULT_MAX_RETRIES = 5 diff --git a/newsdataapi/newsdataapi_client.py b/newsdataapi/newsdataapi_client.py index 54497dc..4a26057 100644 --- a/newsdataapi/newsdataapi_client.py +++ b/newsdataapi/newsdataapi_client.py @@ -34,6 +34,7 @@ def set_base_url(self,new_base_url:str=constants.BASE_URL)->None: self.crypto_url = urljoin(new_base_url,constants.CRYPTO_ENDPOINT) self.sources_url = urljoin(new_base_url,constants.SOURCES_ENDPOINT) self.count_url = urljoin(new_base_url,constants.COUNT_ENDPOINT) + self.crypto_count_url = urljoin(new_base_url,constants.CRYPTO_COUNT_ENDPOINT) def set_retries( self, max_retries:int, retry_delay:int)->None: """ API maximum retry and delay""" @@ -323,6 +324,22 @@ def count_api( URL_parameters = self.__validate_parms(user_param=params) URL_parameters_encoded = urlencode(URL_parameters, quote_via=quote) return self.__get_feeds(url=f'{self.count_url}?{URL_parameters_encoded}') + + def crypto_count_api( + self, q:Optional[str]=None, qInTitle:Optional[str]=None, qInMeta:Optional[str]=None,language:Optional[Union[str, list]]=None, + from_date:Optional[str]=None,to_date:Optional[str]=None,coin:Optional[str]=None,raw_query:Optional[str]=None + ) -> dict: + """ + Sending GET request to the crypto count api + For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation + """ + params = { + 'q':q,'qInTitle':qInTitle,'language':language,'from_date':from_date,'to_date':to_date,'coin':coin, + 'apikey':self.apikey,'qInMeta':qInMeta,'raw_query':raw_query + } + URL_parameters = self.__validate_parms(user_param=params) + URL_parameters_encoded = urlencode(URL_parameters, quote_via=quote) + return self.__get_feeds(url=f'{self.crypto_count_url}?{URL_parameters_encoded}') def __del__(self): if isinstance(self.request_method,requests.Session): diff --git a/setup.py b/setup.py index a8c7bec..3267efc 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='newsdataapi', - version='0.1.25', + version='0.1.26', packages=['newsdataapi'], description='Python library for newsdata client-API Call', long_description=long_description, diff --git a/tests/test_newsdataapi.py b/tests/test_newsdataapi.py index 8e2174d..c0a5430 100644 --- a/tests/test_newsdataapi.py +++ b/tests/test_newsdataapi.py @@ -32,7 +32,10 @@ def test_crypto_api(self): self.assertEqual(response['status'], "success") - # def test_count_api(self): - # response = self.api.count_api(language='en') + def test_count_api(self): + response = self.api.count_api(language='en') + self.assertEqual(response['status'], "success") - # self.assertEqual(response['status'], "success") + def test_crypto_count_api(self): + response = self.api.crypto_count_api(q='bitcoin',language='en') + self.assertEqual(response['status'], "success")