|
1 | 1 | import requests |
2 | 2 | from newsapi.newsapi_auth import NewsApiAuth |
3 | 3 | from newsapi import const |
| 4 | +from newsapi import utils |
4 | 5 | from newsapi.newsapi_exception import NewsAPIException |
5 | 6 | from sys import version_info |
6 | 7 |
|
@@ -145,10 +146,12 @@ def get_everything(self, q=None, sources=None, domains=None, exclude_domains=Non |
145 | 146 |
|
146 | 147 | (str) exclude_domains - A comma_seperated string of domains to be excluded from the search |
147 | 148 |
|
148 | | - (str) from_param - A date and optional time for the oldest article allowed. |
149 | | - (e.g. 2018-03-05 or 2018-03-05T03:46:15) |
| 149 | + (str, date, datetime, float, int, or None) |
| 150 | + from_param - A date and optional time for the oldest article allowed. |
| 151 | + (e.g. 2018-03-05 or 2018-03-05T03:46:15) |
150 | 152 |
|
151 | | - (str) to - A date and optional time for the newest article allowed. |
| 153 | + (str, date, datetime, float, int, or None) |
| 154 | + to - A date and optional time for the newest article allowed. |
152 | 155 |
|
153 | 156 | (str) language - The 2-letter ISO-639-1 code of the language you want to get headlines for. Valid values are: |
154 | 157 | 'ar','de','en','es','fr','he','it','nl','no','pt','ru','se','ud','zh' |
@@ -192,31 +195,11 @@ def get_everything(self, q=None, sources=None, domains=None, exclude_domains=Non |
192 | 195 |
|
193 | 196 | # Search From This Date ... |
194 | 197 | if from_param is not None: |
195 | | - if is_valid_string(from_param): |
196 | | - if (len(from_param)) >= 10: |
197 | | - for i in range(len(from_param)): |
198 | | - if (i == 4 and from_param[i] != '-') or (i == 7 and from_param[i] != '-'): |
199 | | - raise ValueError('from_param should be in the format of YYYY-MM-DD') |
200 | | - else: |
201 | | - payload['from'] = from_param |
202 | | - else: |
203 | | - raise ValueError('from_param should be in the format of YYYY-MM-DD') |
204 | | - else: |
205 | | - raise TypeError('from_param should be of type str') |
| 198 | + payload['from'] = utils.stringify_date_param(from_param) |
206 | 199 |
|
207 | 200 | # ... To This Date |
208 | 201 | if to is not None: |
209 | | - if is_valid_string(to): |
210 | | - if (len(to)) >= 10: |
211 | | - for i in range(len(to)): |
212 | | - if (i == 4 and to[i] != '-') or (i == 7 and to[i] != '-'): |
213 | | - raise ValueError('to should be in the format of YYYY-MM-DD') |
214 | | - else: |
215 | | - payload['to'] = to |
216 | | - else: |
217 | | - raise ValueError('to param should be in the format of YYYY-MM-DD') |
218 | | - else: |
219 | | - raise TypeError('to param should be of type str') |
| 202 | + payload['to'] = utils.stringify_date_param(to) |
220 | 203 |
|
221 | 204 | # Language |
222 | 205 | if language is not None: |
|
0 commit comments