newsdataapi 0.1.28__tar.gz → 0.1.30__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {newsdataapi-0.1.28/newsdataapi.egg-info → newsdataapi-0.1.30}/PKG-INFO +1 -1
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/constants.py +2 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/newsdataapi_client.py +271 -79
- {newsdataapi-0.1.28 → newsdataapi-0.1.30/newsdataapi.egg-info}/PKG-INFO +1 -1
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/setup.py +1 -1
- newsdataapi-0.1.30/tests/test_newsdataapi.py +62 -0
- newsdataapi-0.1.28/tests/test_newsdataapi.py +0 -45
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/LICENSE +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/MANIFEST.in +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/README.md +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/__init__.py +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/helpers.py +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/newsdataapi_exception.py +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi/utils.py +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi.egg-info/SOURCES.txt +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi.egg-info/dependency_links.txt +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi.egg-info/requires.txt +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/newsdataapi.egg-info/top_level.txt +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/requirements.txt +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/setup.cfg +0 -0
- {newsdataapi-0.1.28 → newsdataapi-0.1.30}/tests/__init__.py +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from warnings import warn
|
|
2
|
+
from typing import Optional
|
|
2
3
|
import requests,time,logging
|
|
3
|
-
from typing import Dict, Any, List
|
|
4
4
|
from newsdataapi import constants
|
|
5
|
-
from typing import
|
|
6
|
-
from datetime import datetime,timezone
|
|
5
|
+
from typing import Dict, Any, List,Union
|
|
7
6
|
from newsdataapi.helpers import FileHandler
|
|
8
7
|
from requests.exceptions import RequestException
|
|
9
8
|
from newsdataapi.newsdataapi_exception import NewsdataException
|
|
@@ -26,11 +25,12 @@ class NewsDataApiClient(FileHandler):
|
|
|
26
25
|
max_pages: Optional[int] = 10**10,
|
|
27
26
|
debug: Optional[bool] = False,
|
|
28
27
|
folder_path: Optional[str] = None,
|
|
29
|
-
include_headers: Optional[bool] = False
|
|
28
|
+
include_headers: Optional[bool] = False,
|
|
29
|
+
accept_language: Optional[str] = 'en',
|
|
30
30
|
) -> None:
|
|
31
31
|
"""Initializes newsdata client object for access Newsdata APIs."""
|
|
32
32
|
self.apikey = apikey
|
|
33
|
-
self.request_method
|
|
33
|
+
self.request_method = requests.Session() if session else requests
|
|
34
34
|
self.max_result = max_result
|
|
35
35
|
self.max_pages = max_pages
|
|
36
36
|
self.max_retries = max_retries
|
|
@@ -40,8 +40,10 @@ class NewsDataApiClient(FileHandler):
|
|
|
40
40
|
self.request_timeout = request_timeout
|
|
41
41
|
# self.is_debug = debug
|
|
42
42
|
self.include_headers = include_headers
|
|
43
|
+
self.accept_language = accept_language
|
|
43
44
|
self.set_base_url()
|
|
44
45
|
super().__init__(folder_path=folder_path)
|
|
46
|
+
logger.info("NewsDataApiClient initialized successfully.")
|
|
45
47
|
|
|
46
48
|
def set_base_url(self,new_base_url:Optional[str]=constants.BASE_URL)->None:
|
|
47
49
|
self.latest_url = urljoin(new_base_url,constants.LATEST_ENDPOINT)
|
|
@@ -51,31 +53,37 @@ class NewsDataApiClient(FileHandler):
|
|
|
51
53
|
self.count_url = urljoin(new_base_url,constants.COUNT_ENDPOINT)
|
|
52
54
|
self.crypto_count_url = urljoin(new_base_url,constants.CRYPTO_COUNT_ENDPOINT)
|
|
53
55
|
self.market_url = urljoin(new_base_url,constants.MARKET_ENDPOINT)
|
|
56
|
+
self.market_count_url = urljoin(new_base_url,constants.MARKET_COUNT_ENDPOINT)
|
|
54
57
|
|
|
55
58
|
def set_retries( self, max_retries:int, retry_delay:int)->None:
|
|
56
59
|
""" API maximum retry and delay"""
|
|
57
60
|
self.max_retries = max_retries
|
|
58
61
|
self.retry_delay = retry_delay
|
|
62
|
+
logger.info(f"Set max_retries to {max_retries} and retry_delay to {retry_delay} seconds.")
|
|
59
63
|
|
|
60
64
|
def set_request_timeout( self, request_timeout:int)->None:
|
|
61
65
|
""" API maximum timeout for the request """
|
|
62
66
|
self.request_timeout = request_timeout
|
|
67
|
+
logger.info(f"Set request_timeout to {request_timeout} seconds.")
|
|
63
68
|
|
|
64
69
|
def api_proxies( self, proxies:dict)->None:
|
|
65
70
|
""" Configure Proxie dictionary """
|
|
66
71
|
self.proxies = proxies
|
|
72
|
+
logger.info(f"Proxies set to: {proxies}")
|
|
67
73
|
|
|
68
74
|
def set_pagination_delay( self, pagination_delay:int)->None:
|
|
69
75
|
""" Set delay between paginated requests """
|
|
70
76
|
self.pagination_delay = pagination_delay
|
|
77
|
+
logger.info(f"Set pagination_delay to {pagination_delay} seconds.")
|
|
71
78
|
|
|
72
79
|
def __validate_parms(self, user_param: Dict[str, Any]) -> Dict[str, Any]:
|
|
73
80
|
bool_params = {'full_content','image','video','removeduplicate'}
|
|
74
81
|
int_params = {'size'}
|
|
75
82
|
string_params = {
|
|
76
|
-
'q','qInTitle','country','category','language','domain','domainurl','excludedomain','timezone',
|
|
83
|
+
'q','qInTitle','country','category','language','domain','domainurl','excludedomain','timezone',
|
|
77
84
|
'from_date','to_date','qInMeta','prioritydomain','timeframe','tag','sentiment','region','coin',
|
|
78
|
-
'excludefield','excludecategory','id','excludelanguage','organization','url','sort','symbol',
|
|
85
|
+
'excludefield','excludecategory','id','excludelanguage','organization','url','sort','symbol',
|
|
86
|
+
'excludecountry','page','interval'
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
def validate_url(url:str)-> str:
|
|
@@ -131,9 +139,15 @@ class NewsDataApiClient(FileHandler):
|
|
|
131
139
|
params = query_params.copy()
|
|
132
140
|
params['apikey'] = self.apikey
|
|
133
141
|
url = f"{endpoint}?{urlencode(params, quote_via=quote)}"
|
|
142
|
+
headers = {'Accept-Language':self.accept_language}
|
|
134
143
|
|
|
135
144
|
logger.info(f"Fetching data from URL: {url}")
|
|
136
|
-
response = self.request_method.get(
|
|
145
|
+
response = self.request_method.get(
|
|
146
|
+
url=url,
|
|
147
|
+
proxies=self.proxies,
|
|
148
|
+
timeout=self.request_timeout,
|
|
149
|
+
headers=headers
|
|
150
|
+
)
|
|
137
151
|
logger.info(f"Time taken to fetch data: {time.perf_counter() - s_time:.2f} seconds")
|
|
138
152
|
|
|
139
153
|
X_API_Limit_Remaining = response.headers.get("X-API-Limit-Remaining")
|
|
@@ -145,7 +159,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
145
159
|
if (
|
|
146
160
|
response.status_code == 200
|
|
147
161
|
and feeds_data.get('status') == 'success'
|
|
148
|
-
and
|
|
162
|
+
and feeds_data.get('results') is not None
|
|
149
163
|
):
|
|
150
164
|
if self.include_headers:
|
|
151
165
|
feeds_data['response_headers'] = dict(response.headers)
|
|
@@ -184,6 +198,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
184
198
|
max_result = self.max_result
|
|
185
199
|
|
|
186
200
|
self.request_method = requests.Session()
|
|
201
|
+
logger.info('Switched to Session for scrolling through all results.')
|
|
187
202
|
|
|
188
203
|
data = {'totalResults':None,'results':[],'nextPage':None}
|
|
189
204
|
while True:
|
|
@@ -207,19 +222,32 @@ class NewsDataApiClient(FileHandler):
|
|
|
207
222
|
|
|
208
223
|
time.sleep(self.pagination_delay)
|
|
209
224
|
|
|
210
|
-
def __paginate_results(self,endpoint:str,query_params:dict,max_pages: Optional[int] = None):
|
|
225
|
+
def __paginate_results(self,endpoint:str,query_params:dict,max_pages: Optional[int] = None, is_count: Optional[bool] = False):
|
|
211
226
|
if max_pages is None:
|
|
212
227
|
max_pages = self.max_pages
|
|
213
228
|
|
|
214
229
|
self.request_method = requests.Session()
|
|
230
|
+
logger.info('Switched to Session for paginating through results.')
|
|
231
|
+
|
|
215
232
|
current_result_count = 0
|
|
216
233
|
page = 0
|
|
217
234
|
while True:
|
|
218
235
|
response = self.__get_feeds(endpoint=endpoint,query_params=query_params)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
236
|
+
results = response.get('results')
|
|
237
|
+
if is_count:
|
|
238
|
+
if isinstance(results, dict):
|
|
239
|
+
yield response
|
|
240
|
+
return
|
|
241
|
+
|
|
242
|
+
current_result_count += len(results)
|
|
243
|
+
page += 1
|
|
244
|
+
logger.info(f"Result fetched: {current_result_count}, Page: {page}")
|
|
245
|
+
yield response
|
|
246
|
+
else:
|
|
247
|
+
current_result_count += len(results)
|
|
248
|
+
page += 1
|
|
249
|
+
logger.info(f"Total result: {response['totalResults']}, Current result count: {current_result_count}, Page: {page}")
|
|
250
|
+
yield response
|
|
223
251
|
|
|
224
252
|
if page >= max_pages:
|
|
225
253
|
logger.info(f"Reached maximum page limit: {max_pages}, ending pagination.")
|
|
@@ -302,6 +330,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
302
330
|
qInTitle: Optional[str] = None,
|
|
303
331
|
qInMeta: Optional[str] = None,
|
|
304
332
|
country: Optional[Union[str, List[str]]] = None,
|
|
333
|
+
excludecountry: Optional[Union[str, List[str]]] = None,
|
|
305
334
|
category: Optional[Union[str, List[str]]] = None,
|
|
306
335
|
language: Optional[Union[str, List[str]]] = None,
|
|
307
336
|
domain: Optional[Union[str, List[str]]] = None,
|
|
@@ -323,7 +352,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
323
352
|
excludecategory: Optional[Union[str, List[str]]] = None,
|
|
324
353
|
id: Optional[str] = None,
|
|
325
354
|
excludelanguage: Optional[Union[str, List[str]]] = None,
|
|
326
|
-
organization: Optional[str] = None,
|
|
355
|
+
organization: Optional[Union[str, List[str]]] = None,
|
|
327
356
|
url: Optional[str] = None,
|
|
328
357
|
sort: Optional[str] = None,
|
|
329
358
|
|
|
@@ -341,6 +370,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
341
370
|
'q':q,
|
|
342
371
|
'qInTitle':qInTitle,
|
|
343
372
|
'country':country,
|
|
373
|
+
'excludecountry':excludecountry,
|
|
344
374
|
'category':category,
|
|
345
375
|
'language':language,
|
|
346
376
|
'domain':domain,
|
|
@@ -384,6 +414,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
384
414
|
q: Optional[str] = None,
|
|
385
415
|
qInTitle: Optional[str] = None,
|
|
386
416
|
country: Optional[Union[str, List[str]]] = None,
|
|
417
|
+
excludecountry: Optional[Union[str, List[str]]] = None,
|
|
387
418
|
category: Optional[Union[str, List[str]]] = None,
|
|
388
419
|
language: Optional[Union[str, List[str]]] = None,
|
|
389
420
|
domain: Optional[Union[str, List[str]]] = None,
|
|
@@ -420,6 +451,7 @@ class NewsDataApiClient(FileHandler):
|
|
|
420
451
|
'q':q,
|
|
421
452
|
'qInTitle':qInTitle,
|
|
422
453
|
'country':country,
|
|
454
|
+
'excludecountry':excludecountry,
|
|
423
455
|
'category':category,
|
|
424
456
|
'language':language,
|
|
425
457
|
'domain':domain,
|
|
@@ -559,66 +591,6 @@ class NewsDataApiClient(FileHandler):
|
|
|
559
591
|
else:
|
|
560
592
|
return self.__get_feeds(endpoint=self.crypto_url,query_params=URL_parameters)
|
|
561
593
|
|
|
562
|
-
def count_api(
|
|
563
|
-
self,
|
|
564
|
-
q: Optional[str] = None,
|
|
565
|
-
qInTitle: Optional[str] = None,
|
|
566
|
-
qInMeta: Optional[str] = None,
|
|
567
|
-
country: Optional[Union[str, List[str]]] = None,
|
|
568
|
-
category: Optional[Union[str, List[str]]] = None,
|
|
569
|
-
language: Optional[Union[str, List[str]]] = None,
|
|
570
|
-
from_date: Optional[str] = None,
|
|
571
|
-
to_date: Optional[str] = None,
|
|
572
|
-
|
|
573
|
-
raw_query: Optional[str] = None,
|
|
574
|
-
) -> Dict[str, Any]:
|
|
575
|
-
"""
|
|
576
|
-
Sending GET request to the count api
|
|
577
|
-
For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation
|
|
578
|
-
"""
|
|
579
|
-
params = {
|
|
580
|
-
'q':q,
|
|
581
|
-
'qInTitle':qInTitle,
|
|
582
|
-
'country':country,
|
|
583
|
-
'category':category,
|
|
584
|
-
'language':language,
|
|
585
|
-
'from_date':from_date,
|
|
586
|
-
'to_date':to_date,
|
|
587
|
-
'qInMeta':qInMeta,
|
|
588
|
-
'raw_query':raw_query
|
|
589
|
-
}
|
|
590
|
-
URL_parameters = self.__validate_parms(user_param=params)
|
|
591
|
-
return self.__get_feeds(endpoint=self.count_url,query_params=URL_parameters)
|
|
592
|
-
|
|
593
|
-
def crypto_count_api(
|
|
594
|
-
self,
|
|
595
|
-
q: Optional[str] = None,
|
|
596
|
-
qInTitle: Optional[str] = None,
|
|
597
|
-
qInMeta: Optional[str] = None,
|
|
598
|
-
language: Optional[Union[str, List[str]]] = None,
|
|
599
|
-
from_date: Optional[str] = None,
|
|
600
|
-
to_date: Optional[str] = None,
|
|
601
|
-
coin: Optional[Union[str, List[str]]] = None,
|
|
602
|
-
|
|
603
|
-
raw_query: Optional[str] = None,
|
|
604
|
-
) -> Dict[str, Any]:
|
|
605
|
-
"""
|
|
606
|
-
Sending GET request to the crypto count api
|
|
607
|
-
For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation
|
|
608
|
-
"""
|
|
609
|
-
params = {
|
|
610
|
-
'q':q,
|
|
611
|
-
'qInTitle':qInTitle,
|
|
612
|
-
'language':language,
|
|
613
|
-
'from_date':from_date,
|
|
614
|
-
'to_date':to_date,
|
|
615
|
-
'coin':coin,
|
|
616
|
-
'qInMeta':qInMeta,
|
|
617
|
-
'raw_query':raw_query
|
|
618
|
-
}
|
|
619
|
-
URL_parameters = self.__validate_parms(user_param=params)
|
|
620
|
-
return self.__get_feeds(endpoint=self.crypto_count_url,query_params=URL_parameters)
|
|
621
|
-
|
|
622
594
|
def market_api(
|
|
623
595
|
self,
|
|
624
596
|
q: Optional[str] = None,
|
|
@@ -643,13 +615,13 @@ class NewsDataApiClient(FileHandler):
|
|
|
643
615
|
id: Optional[str] = None,
|
|
644
616
|
excludefield: Optional[Union[str, List[str]]] = None,
|
|
645
617
|
removeduplicate: Optional[bool] = None,
|
|
646
|
-
webhook: Optional[str] = None,
|
|
647
618
|
excludelanguage: Optional[Union[str, List[str]]] = None,
|
|
648
|
-
organization: Optional[str] = None,
|
|
619
|
+
organization: Optional[Union[str, List[str]]] = None,
|
|
649
620
|
url: Optional[str] = None,
|
|
650
621
|
sort: Optional[str] = None,
|
|
651
622
|
symbol: Optional[str] = None,
|
|
652
623
|
country: Optional[Union[str, List[str]]] = None,
|
|
624
|
+
excludecountry: Optional[Union[str, List[str]]] = None,
|
|
653
625
|
|
|
654
626
|
max_result: Optional[int] = None,
|
|
655
627
|
scroll: Optional[bool] = False,
|
|
@@ -683,13 +655,13 @@ class NewsDataApiClient(FileHandler):
|
|
|
683
655
|
'id': id,
|
|
684
656
|
'excludefield': excludefield,
|
|
685
657
|
'removeduplicate': removeduplicate,
|
|
686
|
-
'webhook': webhook,
|
|
687
658
|
'excludelanguage': excludelanguage,
|
|
688
659
|
'organization': organization,
|
|
689
660
|
'url': url,
|
|
690
661
|
'sort': sort,
|
|
691
662
|
'symbol': symbol,
|
|
692
|
-
'country': country
|
|
663
|
+
'country': country,
|
|
664
|
+
'excludecountry': excludecountry,
|
|
693
665
|
}
|
|
694
666
|
if scroll and paginate:
|
|
695
667
|
raise NewsdataException("Both 'scroll' and 'paginate' cannot be True at the same time.")
|
|
@@ -701,7 +673,227 @@ class NewsDataApiClient(FileHandler):
|
|
|
701
673
|
return self.__paginate_results(endpoint=self.market_url,query_params=URL_parameters,max_pages=max_pages)
|
|
702
674
|
else:
|
|
703
675
|
return self.__get_feeds(endpoint=self.market_url,query_params=URL_parameters)
|
|
676
|
+
|
|
677
|
+
def count_api(
|
|
678
|
+
self,
|
|
679
|
+
from_date: Optional[str],
|
|
680
|
+
to_date: Optional[str],
|
|
681
|
+
q: Optional[str] = None,
|
|
682
|
+
qInTitle: Optional[str] = None,
|
|
683
|
+
qInMeta: Optional[str] = None,
|
|
684
|
+
country: Optional[Union[str, List[str]]] = None,
|
|
685
|
+
category: Optional[Union[str, List[str]]] = None,
|
|
686
|
+
language: Optional[Union[str, List[str]]] = None,
|
|
687
|
+
domain: Optional[Union[str, List[str]]] = None,
|
|
688
|
+
domainurl: Optional[Union[str, List[str]]] = None,
|
|
689
|
+
excludedomain: Optional[Union[str, List[str]]] = None,
|
|
690
|
+
excludecountry: Optional[Union[str, List[str]]] = None,
|
|
691
|
+
excludelanguage: Optional[Union[str, List[str]]] = None,
|
|
692
|
+
excludecategory: Optional[Union[str, List[str]]] = None,
|
|
693
|
+
full_content: Optional[bool] = None,
|
|
694
|
+
image: Optional[bool] = None,
|
|
695
|
+
page: Optional[str] = None,
|
|
696
|
+
prioritydomain: Optional[str] = None,
|
|
697
|
+
size: Optional[int] = None,
|
|
698
|
+
sort: Optional[str] = None,
|
|
699
|
+
video: Optional[bool] = None,
|
|
700
|
+
interval: Optional[str] = None,
|
|
701
|
+
|
|
702
|
+
raw_query: Optional[str] = None,
|
|
703
|
+
paginate: Optional[bool] = False,
|
|
704
|
+
max_pages: Optional[int] = None,
|
|
705
|
+
) -> Dict[str, Any]:
|
|
706
|
+
"""
|
|
707
|
+
Sending GET request to the count API.
|
|
708
|
+
"""
|
|
709
|
+
|
|
710
|
+
params = {
|
|
711
|
+
'q': q,
|
|
712
|
+
'qInTitle': qInTitle,
|
|
713
|
+
'qInMeta': qInMeta,
|
|
714
|
+
'country': country,
|
|
715
|
+
'category': category,
|
|
716
|
+
'language': language,
|
|
717
|
+
'from_date': from_date,
|
|
718
|
+
'to_date': to_date,
|
|
719
|
+
'domain': domain,
|
|
720
|
+
'domainurl': domainurl,
|
|
721
|
+
'excludedomain': excludedomain,
|
|
722
|
+
'excludecountry': excludecountry,
|
|
723
|
+
'excludelanguage': excludelanguage,
|
|
724
|
+
'excludecategory': excludecategory,
|
|
725
|
+
'full_content': full_content,
|
|
726
|
+
'image': image,
|
|
727
|
+
'page': page,
|
|
728
|
+
'prioritydomain': prioritydomain,
|
|
729
|
+
'size': size,
|
|
730
|
+
'sort': sort,
|
|
731
|
+
'video': video,
|
|
732
|
+
'interval': interval,
|
|
733
|
+
'raw_query': raw_query
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
URL_parameters = self.__validate_parms(user_param=params)
|
|
737
|
+
if paginate:
|
|
738
|
+
return self.__paginate_results(
|
|
739
|
+
endpoint=self.count_url,
|
|
740
|
+
query_params=URL_parameters,
|
|
741
|
+
max_pages=max_pages,
|
|
742
|
+
is_count=True
|
|
743
|
+
)
|
|
744
|
+
else:
|
|
745
|
+
return self.__get_feeds(endpoint=self.count_url,query_params=URL_parameters)
|
|
746
|
+
|
|
747
|
+
def crypto_count_api(
|
|
748
|
+
self,
|
|
749
|
+
from_date: Optional[str],
|
|
750
|
+
to_date: Optional[str],
|
|
751
|
+
q: Optional[str] = None,
|
|
752
|
+
qInTitle: Optional[str] = None,
|
|
753
|
+
qInMeta: Optional[str] = None,
|
|
754
|
+
language: Optional[Union[str, List[str]]] = None,
|
|
755
|
+
coin: Optional[Union[str, List[str]]] = None,
|
|
756
|
+
domain: Optional[Union[str, List[str]]] = None,
|
|
757
|
+
domainurl: Optional[Union[str, List[str]]] = None,
|
|
758
|
+
excludedomain: Optional[Union[str, List[str]]] = None,
|
|
759
|
+
excludelanguage: Optional[Union[str, List[str]]] = None,
|
|
760
|
+
full_content: Optional[bool] = None,
|
|
761
|
+
image: Optional[bool] = None,
|
|
762
|
+
page: Optional[str] = None,
|
|
763
|
+
prioritydomain: Optional[str] = None,
|
|
764
|
+
sentiment: Optional[str] = None,
|
|
765
|
+
size: Optional[int] = None,
|
|
766
|
+
sort: Optional[str] = None,
|
|
767
|
+
tag: Optional[Union[str, List[str]]] = None,
|
|
768
|
+
video: Optional[bool] = None,
|
|
769
|
+
interval: Optional[str] = None,
|
|
770
|
+
removeduplicate: Optional[bool] = None,
|
|
771
|
+
|
|
772
|
+
raw_query: Optional[str] = None,
|
|
773
|
+
paginate: Optional[bool] = False,
|
|
774
|
+
max_pages: Optional[int] = None,
|
|
775
|
+
) -> Dict[str, Any]:
|
|
776
|
+
"""
|
|
777
|
+
Sending GET request to the crypto count api
|
|
778
|
+
Supports all parameters available in v2 crypto_count specification.
|
|
779
|
+
"""
|
|
780
|
+
|
|
781
|
+
params = {
|
|
782
|
+
'q': q,
|
|
783
|
+
'qInTitle': qInTitle,
|
|
784
|
+
'qInMeta': qInMeta,
|
|
785
|
+
'language': language,
|
|
786
|
+
'from_date': from_date,
|
|
787
|
+
'to_date': to_date,
|
|
788
|
+
'coin': coin,
|
|
789
|
+
'domain': domain,
|
|
790
|
+
'domainurl': domainurl,
|
|
791
|
+
'excludedomain': excludedomain,
|
|
792
|
+
'excludelanguage': excludelanguage,
|
|
793
|
+
'full_content': full_content,
|
|
794
|
+
'image': image,
|
|
795
|
+
'page': page,
|
|
796
|
+
'prioritydomain': prioritydomain,
|
|
797
|
+
'sentiment': sentiment,
|
|
798
|
+
'size': size,
|
|
799
|
+
'sort': sort,
|
|
800
|
+
'tag': tag,
|
|
801
|
+
'video': video,
|
|
802
|
+
'interval': interval,
|
|
803
|
+
'removeduplicate': removeduplicate,
|
|
804
|
+
'raw_query': raw_query,
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
URL_parameters = self.__validate_parms(user_param=params)
|
|
808
|
+
if paginate:
|
|
809
|
+
return self.__paginate_results(
|
|
810
|
+
endpoint=self.crypto_count_url,
|
|
811
|
+
query_params=URL_parameters,
|
|
812
|
+
max_pages=max_pages,
|
|
813
|
+
is_count=True
|
|
814
|
+
)
|
|
815
|
+
else:
|
|
816
|
+
return self.__get_feeds(endpoint=self.crypto_count_url,query_params=URL_parameters)
|
|
817
|
+
|
|
818
|
+
def market_count_api(
|
|
819
|
+
self,
|
|
820
|
+
from_date: Optional[str],
|
|
821
|
+
to_date: Optional[str],
|
|
822
|
+
q: Optional[str] = None,
|
|
823
|
+
qInTitle: Optional[str] = None,
|
|
824
|
+
qInMeta: Optional[str] = None,
|
|
825
|
+
country: Optional[Union[str, List[str]]] = None,
|
|
826
|
+
domain: Optional[Union[str, List[str]]] = None,
|
|
827
|
+
domainurl: Optional[Union[str, List[str]]] = None,
|
|
828
|
+
excludedomain: Optional[Union[str, List[str]]] = None,
|
|
829
|
+
excludecountry: Optional[Union[str, List[str]]] = None,
|
|
830
|
+
excludelanguage: Optional[Union[str, List[str]]] = None,
|
|
831
|
+
full_content: Optional[bool] = None,
|
|
832
|
+
image: Optional[bool] = None,
|
|
833
|
+
language: Optional[Union[str, List[str]]] = None,
|
|
834
|
+
organization: Optional[Union[str, List[str]]] = None,
|
|
835
|
+
page: Optional[str] = None,
|
|
836
|
+
prioritydomain: Optional[str] = None,
|
|
837
|
+
removeduplicate: Optional[bool] = None,
|
|
838
|
+
sentiment: Optional[str] = None,
|
|
839
|
+
size: Optional[int] = None,
|
|
840
|
+
sort: Optional[str] = None,
|
|
841
|
+
tag: Optional[Union[str, List[str]]] = None,
|
|
842
|
+
video: Optional[bool] = None,
|
|
843
|
+
symbol: Optional[Union[str, List[str]]] = None,
|
|
844
|
+
interval: Optional[str] = None,
|
|
845
|
+
|
|
846
|
+
raw_query: Optional[str] = None,
|
|
847
|
+
paginate: Optional[bool] = False,
|
|
848
|
+
max_pages: Optional[int] = None,
|
|
849
|
+
) -> Dict[str, Any]:
|
|
850
|
+
"""
|
|
851
|
+
Sending GET request to the Market Count API.
|
|
852
|
+
Supports all parameters available in the market_count specification.
|
|
853
|
+
"""
|
|
854
|
+
|
|
855
|
+
params = {
|
|
856
|
+
'q': q,
|
|
857
|
+
'qInTitle': qInTitle,
|
|
858
|
+
'qInMeta': qInMeta,
|
|
859
|
+
'country': country,
|
|
860
|
+
'domain': domain,
|
|
861
|
+
'domainurl': domainurl,
|
|
862
|
+
'excludedomain': excludedomain,
|
|
863
|
+
'excludecountry': excludecountry,
|
|
864
|
+
'excludelanguage': excludelanguage,
|
|
865
|
+
'from_date': from_date,
|
|
866
|
+
'to_date': to_date,
|
|
867
|
+
'full_content': full_content,
|
|
868
|
+
'image': image,
|
|
869
|
+
'language': language,
|
|
870
|
+
'organization': organization,
|
|
871
|
+
'page': page,
|
|
872
|
+
'prioritydomain': prioritydomain,
|
|
873
|
+
'removeduplicate': removeduplicate,
|
|
874
|
+
'sentiment': sentiment,
|
|
875
|
+
'size': size,
|
|
876
|
+
'sort': sort,
|
|
877
|
+
'tag': tag,
|
|
878
|
+
'video': video,
|
|
879
|
+
'symbol': symbol,
|
|
880
|
+
'interval': interval,
|
|
881
|
+
'raw_query': raw_query,
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
URL_parameters = self.__validate_parms(user_param=params)
|
|
885
|
+
|
|
886
|
+
if paginate:
|
|
887
|
+
return self.__paginate_results(
|
|
888
|
+
endpoint=self.market_count_url,
|
|
889
|
+
query_params=URL_parameters,
|
|
890
|
+
max_pages=max_pages,
|
|
891
|
+
is_count=True
|
|
892
|
+
)
|
|
893
|
+
|
|
894
|
+
return self.__get_feeds(endpoint=self.market_count_url,query_params=URL_parameters)
|
|
704
895
|
|
|
705
896
|
def __del__(self):
|
|
706
897
|
if isinstance(self.request_method,requests.Session):
|
|
707
898
|
self.request_method.close()
|
|
899
|
+
logger.info("Closed the requests Session.")
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import os,unittest,datetime
|
|
2
|
+
from newsdataapi import NewsDataApiClient
|
|
3
|
+
|
|
4
|
+
class test_newsdataapi(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def setUp(self):
|
|
7
|
+
# your private API key.
|
|
8
|
+
key = os.environ.get("PYTEST_TOKEN")
|
|
9
|
+
self.api = NewsDataApiClient(apikey=key)
|
|
10
|
+
|
|
11
|
+
def test_news_api(self):
|
|
12
|
+
response = self.api.news_api()
|
|
13
|
+
|
|
14
|
+
self.assertEqual(response['status'], "success")
|
|
15
|
+
|
|
16
|
+
def test_latest_api(self):
|
|
17
|
+
response = self.api.latest_api()
|
|
18
|
+
|
|
19
|
+
self.assertEqual(response['status'], "success")
|
|
20
|
+
|
|
21
|
+
def test_archive_api(self):
|
|
22
|
+
response = self.api.archive_api(q='news')
|
|
23
|
+
|
|
24
|
+
self.assertEqual(response['status'], "success")
|
|
25
|
+
|
|
26
|
+
def test_sources_api(self):
|
|
27
|
+
response = self.api.sources_api()
|
|
28
|
+
|
|
29
|
+
self.assertEqual(response['status'], "success")
|
|
30
|
+
|
|
31
|
+
def test_crypto_api(self):
|
|
32
|
+
response = self.api.crypto_api(q='bitcoin')
|
|
33
|
+
|
|
34
|
+
self.assertEqual(response['status'], "success")
|
|
35
|
+
|
|
36
|
+
def test_market_api(self):
|
|
37
|
+
response = self.api.market_api()
|
|
38
|
+
self.assertEqual(response['status'], "success")
|
|
39
|
+
|
|
40
|
+
def test_count_api(self):
|
|
41
|
+
current_dt = datetime.datetime.now()
|
|
42
|
+
from_date = (current_dt - datetime.timedelta(days=30)).strftime('%Y-%m-%d 00:00:00')
|
|
43
|
+
to_date = current_dt.strftime('%Y-%m-%d 00:00:00')
|
|
44
|
+
parms = {'language':'en','from_date':from_date,'to_date':to_date,}
|
|
45
|
+
response = self.api.count_api(**parms)
|
|
46
|
+
self.assertEqual(response['status'], "success")
|
|
47
|
+
|
|
48
|
+
def test_crypto_count_api(self):
|
|
49
|
+
current_dt = datetime.datetime.now()
|
|
50
|
+
from_date = (current_dt - datetime.timedelta(days=30)).strftime('%Y-%m-%d 00:00:00')
|
|
51
|
+
to_date = current_dt.strftime('%Y-%m-%d 00:00:00')
|
|
52
|
+
parms = {'language':'en','from_date':from_date,'to_date':to_date,}
|
|
53
|
+
response = self.api.crypto_count_api(**parms)
|
|
54
|
+
self.assertEqual(response['status'], "success")
|
|
55
|
+
|
|
56
|
+
def test_market_count_api(self):
|
|
57
|
+
current_dt = datetime.datetime.now()
|
|
58
|
+
from_date = (current_dt - datetime.timedelta(days=30)).strftime('%Y-%m-%d 00:00:00')
|
|
59
|
+
to_date = current_dt.strftime('%Y-%m-%d 00:00:00')
|
|
60
|
+
parms = {'language':'en','from_date':from_date,'to_date':to_date,}
|
|
61
|
+
response = self.api.market_count_api(**parms)
|
|
62
|
+
self.assertEqual(response['status'], "success")
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import os,unittest
|
|
2
|
-
from newsdataapi import NewsDataApiClient
|
|
3
|
-
|
|
4
|
-
class test_newsdataapi(unittest.TestCase):
|
|
5
|
-
def setUp(self):
|
|
6
|
-
# your private API key.
|
|
7
|
-
key = os.environ.get("PYTEST_TOKEN")
|
|
8
|
-
self.api = NewsDataApiClient(apikey=key)
|
|
9
|
-
|
|
10
|
-
def test_news_api(self):
|
|
11
|
-
response = self.api.news_api()
|
|
12
|
-
|
|
13
|
-
self.assertEqual(response['status'], "success")
|
|
14
|
-
|
|
15
|
-
def test_latest_api(self):
|
|
16
|
-
response = self.api.latest_api()
|
|
17
|
-
|
|
18
|
-
self.assertEqual(response['status'], "success")
|
|
19
|
-
|
|
20
|
-
def test_archive_api(self):
|
|
21
|
-
response = self.api.archive_api(q='test')
|
|
22
|
-
|
|
23
|
-
self.assertEqual(response['status'], "success")
|
|
24
|
-
|
|
25
|
-
def test_sources_api(self):
|
|
26
|
-
response = self.api.sources_api()
|
|
27
|
-
|
|
28
|
-
self.assertEqual(response['status'], "success")
|
|
29
|
-
|
|
30
|
-
def test_crypto_api(self):
|
|
31
|
-
response = self.api.crypto_api()
|
|
32
|
-
|
|
33
|
-
self.assertEqual(response['status'], "success")
|
|
34
|
-
|
|
35
|
-
def test_count_api(self):
|
|
36
|
-
response = self.api.count_api(language='en')
|
|
37
|
-
self.assertEqual(response['status'], "success")
|
|
38
|
-
|
|
39
|
-
def test_crypto_count_api(self):
|
|
40
|
-
response = self.api.crypto_count_api(q='bitcoin',language='en')
|
|
41
|
-
self.assertEqual(response['status'], "success")
|
|
42
|
-
|
|
43
|
-
def test_market_api(self):
|
|
44
|
-
response = self.api.market_api()
|
|
45
|
-
self.assertEqual(response['status'], "success")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|