Skip to content

Commit f4a67b5

Browse files
author
himanshu
committed
added coin support in crypto endpoint and changes in readme file
1 parent bd9e5a7 commit f4a67b5

3 files changed

Lines changed: 22 additions & 194 deletions

File tree

README.md

Lines changed: 6 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,21 @@
11

2-
![Alt text](https://raw.githubusercontent.com/newsdataapi/python-client/main/newsdata-logo.png)
2+
[![NewsData.io logo](newsdata-logo.png)](https://newsdata.io)
33

44
# <p align="center">NewsData.io Python Client
5+
56
newsdataapi allows you to create a library for accessing http services easily, in a centralized way. An API defined by newsdataapi will return a JSON object when called.
67

7-
[![Build Status](https://img.shields.io/github/workflow/status/newsdataapi/python-client/Upload%20Python%20Package)](https://github.com/newsdataapi/python-client/actions/workflows/python-publish.yml)
8+
[![Build Status](https://img.shields.io/github/actions/workflow/status/bytesview/python-client/python-publish.yml)](https://github.com/bytesview/python-client/actions/workflows/python-publish.yml)
89
[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/newsdataapi/python-client/blob/main/LICENSE)
910
[![PyPI](https://img.shields.io/pypi/v/newsdataapi?color=084298)](https://pypi.org/project/newsdataapi)
11+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/newsdataapi)](https://pypi.org/project/newsdataapi)
1012
[![Supported Python versions](https://img.shields.io/pypi/pyversions/newsdataapi)](https://pypi.org/project/newsdataapi)
11-
[![Python](https://img.shields.io/badge/python-3-blue)](https://pypi.org/project/newsdataapi)
12-
13-
14-
<br />
1513

16-
# Installation
17-
18-
## Supported Python Versions
19-
Python >= 3.5 fully supported and tested.
20-
21-
## Install Package
14+
## Installation
2215
```
2316
pip install newsdataapi
2417
```
2518

2619
## Documentation
2720

28-
Newsdataapi docs can be seen [here](https://newsdata.io/documentation).
29-
30-
<br />
31-
32-
### Latest News API
33-
34-
`GET /1/news`
35-
36-
```
37-
# To get latest news use our news_api method.
38-
39-
from newsdataapi import NewsDataApiClient
40-
41-
# API key authorization, Initialize the client with your API key
42-
43-
api = NewsDataApiClient(apikey='YOUR_API_KEY')
44-
response = api.news_api(q='entertainment')
45-
print(response)
46-
47-
# Latest news with page parameter
48-
49-
response = api.news_api(q='entertainment',page='nextPage_value')
50-
print(response)
51-
52-
# To scroll through all latest news
53-
54-
response = api.news_api(q='entertainment',page='nextPage_value',scroll=True)
55-
print(response)
56-
57-
```
58-
<br />
59-
60-
### News Archive API
61-
62-
`GET /1/archive`
63-
64-
```
65-
# To get archive news use our archive_api method.
66-
67-
from newsdataapi import NewsDataApiClient
68-
69-
# API key authorization, Initialize the client with your API key
70-
71-
api = NewsDataApiClient(apikey='YOUR_API_KEY')
72-
response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06')
73-
print(response)
74-
75-
# Archive news with page parameter
76-
77-
response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06',page='nextPage_value')
78-
print(response)
79-
80-
# To scroll through all archive news
81-
82-
response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06',page='nextPage_value',scroll=True)
83-
print(response)
84-
85-
```
86-
<br />
87-
88-
89-
### News Sources API
90-
91-
`GET /1/sources`
92-
93-
```
94-
# To get sources use our sources_api method.
95-
96-
from newsdataapi import NewsDataApiClient
97-
98-
# API key authorization, Initialize the client with your API key
99-
100-
api = NewsDataApiClient(apikey="YOUR_API_KEY")
101-
response = api.sources_api()
102-
print(response)
103-
104-
```
105-
<br />
106-
107-
### Crypto News API
108-
109-
`GET /1/crypto`
110-
111-
```
112-
# To get crypto news use our crypto_api method.
113-
114-
from newsdataapi import NewsDataApiClient
115-
116-
# API key authorization, Initialize the client with your API key
117-
118-
api = NewsDataApiClient(apikey='YOUR_API_KEY')
119-
response = api.crypto_api(q='bitcoin')
120-
print(response)
121-
122-
# Crypto with page parameter
123-
124-
response = api.crypto_api(q='bitcoin',page='nextPage_value')
125-
print(response)
126-
127-
# To scroll through all crypto news
128-
129-
response = api.crypto_api(q='bitcoin',page='nextPage_value',scroll=True)
130-
print(response)
131-
132-
```
133-
<br />
134-
135-
### News API with Pagination
136-
137-
`GET /1/news`
138-
139-
```
140-
from newsdataapi import NewsDataApiClient
141-
142-
# API key authorization, Initialize the client with your API key
143-
144-
api = NewsDataApiClient(apikey="YOUR_API_KEY")
145-
response = api.news_api()
146-
147-
# You can go to next page by providing Page parameter
148-
149-
response = api.news_api(page = "nextPage value")
150-
151-
# You can paginate till last page by providing Page parameter in Loop
152-
153-
page=None
154-
while True:
155-
response = api.news_api(page = page)
156-
page = response.get('nextPage',None)
157-
if not page:
158-
break
159-
160-
```
161-
162-
<br />
163-
164-
### News API with Scrolling
165-
166-
```
167-
# Note: Scrolling through all result will counsume api as per your defined size. you can also define max_result to stop scrolling at desired result size.scroll is avaliable in news_archive,news_api and news_crypto, it will return all result when scrolling is compleated.
168-
169-
from newsdataapi import NewsDataApiClient
170-
171-
# API key authorization, Initialize the client with your API key
172-
173-
api = NewsDataApiClient(apikey="YOUR_API_KEY")
174-
175-
response = api.news_api(q='entertainment',page='nextPage_value',scroll=True,max_result=1000)
176-
print(response)
177-
178-
```
179-
180-
<br />
181-
182-
## License
183-
184-
Provided under [MIT License](https://github.com/newsdataapi/python-client/blob/main/LICENSE) by Matt Lisivick.
185-
186-
```
187-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
188-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
189-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
190-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
191-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
192-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
193-
```
21+
Newsdataapi docs can be seen [here](https://newsdata.io/documentation)

newsdataapi/newsdataapi_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests,time
2-
from datetime import datetime
32
from newsdataapi import constants
43
from typing import Optional,Union
4+
from datetime import datetime,timezone
55
from urllib.parse import urlencode, quote
66
from newsdataapi.newsdataapi_exception import NewsdataException
77

@@ -40,7 +40,7 @@ def __validate_parms(self,param:str,value:Union[list,int,str,bool])->dict:
4040
int_params = {'size'}
4141
string_params = {
4242
'q','qInTitle','country','category','language','domain','domainurl','excludedomain','timezone','page',
43-
'from_date','to_date','apikey','qInMeta','prioritydomain','timeframe','tag','sentiment','region'
43+
'from_date','to_date','apikey','qInMeta','prioritydomain','timeframe','tag','sentiment','region','coin'
4444
}
4545

4646
if param in string_params:
@@ -61,28 +61,28 @@ def __validate_parms(self,param:str,value:Union[list,int,str,bool])->dict:
6161
def __get_feeds(self,url:str)-> dict:
6262
try:
6363
if self.recursive_retry <= 0:
64-
raise NewsdataException('maximum retry limit reached.')
64+
raise NewsdataException('Maximum retry limit reached. For more information use debug parameter while initializing NewsDataApiClient.')
6565
response = self.request_method.get(url=url,proxies=self.proxies,timeout=self.request_timeout)
6666
if self.is_debug == True:
6767
headers = response.headers
68-
print(f'Debug | {datetime.utcnow().replace(microsecond=0)} | x_rate_limit_remaining: {headers.get("x_rate_limit_remaining")} | x_api_limit_remaining: {headers.get("x_api_limit_remaining")}')
68+
print(f'Debug | {datetime.now(tz=timezone.utc).replace(microsecond=0)} | x_rate_limit_remaining: {headers.get("x_rate_limit_remaining")} | x_api_limit_remaining: {headers.get("x_api_limit_remaining")}')
6969
feeds_data:dict = response.json()
7070
if response.status_code != 200:
7171
if response.status_code == 500:
7272
if self.is_debug == True:
73-
print(f"Debug | {datetime.utcnow().replace(microsecond=0)} | Encountered 'ServerError' going to sleep for: {self.retry_delay} seconds.")
73+
print(f"Debug | {datetime.now(tz=timezone.utc).replace(microsecond=0)} | Encountered 'ServerError' going to sleep for: {self.retry_delay} seconds.")
7474
time.sleep(self.retry_delay)
7575
self.recursive_retry-=1
7676
return self.__get_feeds(url=url)
7777
elif feeds_data.get('results',{}).get('code') == 'TooManyRequests':
7878
if self.is_debug == True:
79-
print(f"Debug | {datetime.utcnow().replace(microsecond=0)} | Encountered 'TooManyRequests' going to sleep for: {constants.DEFAULT_RETRY_DELAY_TooManyRequests} seconds.")
79+
print(f"Debug | {datetime.now(tz=timezone.utc).replace(microsecond=0)} | Encountered 'TooManyRequests' going to sleep for: {constants.DEFAULT_RETRY_DELAY_TooManyRequests} seconds.")
8080
time.sleep(constants.DEFAULT_RETRY_DELAY_TooManyRequests)
8181
self.recursive_retry-=1
8282
return self.__get_feeds(url=url)
8383
elif feeds_data.get('results',{}).get('code') == 'RateLimitExceeded':
8484
if self.is_debug == True:
85-
print(f"Debug | {datetime.utcnow().replace(microsecond=0)} | Encountered 'RateLimitExceeded' going to sleep for: {constants.DEFAULT_RETRY_DELAY_RateLimitExceeded} seconds.")
85+
print(f"Debug | {datetime.now(tz=timezone.utc).replace(microsecond=0)} | Encountered 'RateLimitExceeded' going to sleep for: {constants.DEFAULT_RETRY_DELAY_RateLimitExceeded} seconds.")
8686
time.sleep(constants.DEFAULT_RETRY_DELAY_RateLimitExceeded)
8787
self.recursive_retry-=1
8888
return self.__get_feeds(url=url)
@@ -195,21 +195,21 @@ def sources_api( self, country:Optional[str]= None, category:Optional[str]= None
195195
return self.__get_feeds(url=f'{constants.SOURCES_URL}?{URL_parameters_encoded}')
196196

197197
def crypto_api(
198-
self, q:Optional[str]=None, qInTitle:Optional[str]=None, country:Optional[Union[str, list]]=None, category:Optional[Union[str, list]]=None,
199-
language:Optional[Union[str, list]]=None, domain:Optional[Union[str, list]]=None, timeframe:Optional[Union[int,str]]=None, size:Optional[int]=None,
200-
domainurl:Optional[Union[str, list]]=None, excludedomain:Optional[Union[str, list]]=None, timezone:Optional[str]=None, full_content:Optional[bool]=None,
201-
image:Optional[bool]=None, video:Optional[bool]=None, prioritydomain:Optional[str]=None, page:Optional[str]=None, scroll:Optional[bool]=False,
202-
max_result:Optional[int]=None, qInMeta:Optional[str]=None,tag:Optional[Union[str,list]]=None, sentiment:Optional[str]=None,
198+
self, q:Optional[str]=None, qInTitle:Optional[str]=None,language:Optional[Union[str, list]]=None, domain:Optional[Union[str, list]]=None,
199+
timeframe:Optional[Union[int,str]]=None, size:Optional[int]=None,domainurl:Optional[Union[str, list]]=None, excludedomain:Optional[Union[str, list]]=None,
200+
timezone:Optional[str]=None, full_content:Optional[bool]=None,image:Optional[bool]=None, video:Optional[bool]=None, prioritydomain:Optional[str]=None,
201+
page:Optional[str]=None, scroll:Optional[bool]=False,max_result:Optional[int]=None, qInMeta:Optional[str]=None,tag:Optional[Union[str,list]]=None,
202+
sentiment:Optional[str]=None,coin:Optional[Union[str, list]]=None
203203
)->dict:
204204
"""
205205
Sending GET request to the crypto api
206206
For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation
207207
"""
208208

209209
params = {
210-
'apikey':self.apikey,'q':q,'qInTitle':qInTitle,'country':country,'category':category,'language':language,'domain':domain,'size':size,'domainurl':domainurl,
210+
'apikey':self.apikey,'q':q,'qInTitle':qInTitle,'language':language,'domain':domain,'size':size,'domainurl':domainurl,
211211
'excludedomain':excludedomain,'timezone':timezone,'full_content':full_content,'image':image,'video':video,'prioritydomain':prioritydomain,'page':page,
212-
'timeframe':str(timeframe) if timeframe else timeframe,'qInMeta':qInMeta,'tag':tag, 'sentiment':sentiment
212+
'timeframe':str(timeframe) if timeframe else timeframe,'qInMeta':qInMeta,'tag':tag, 'sentiment':sentiment,'coin':coin
213213
}
214214

215215
URL_parameters = {}

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from setuptools import find_packages, setup
1+
from setuptools import setup
22

33
with open("README.md", "r") as fh:
44
long_description = fh.read()
55

66

77
setup(
88
name='newsdataapi',
9-
version='0.1.11',
9+
version='0.1.12',
1010
packages=['newsdataapi'],
1111
description='Python library for newsdata client-API Call',
1212
long_description=long_description,

0 commit comments

Comments
 (0)