11import requests ,time
2+ from warnings import warn
23from newsdataapi import constants
34from typing import Optional ,Union
45from datetime import datetime ,timezone
@@ -159,6 +160,7 @@ def news_api(
159160 Sending GET request to the news api.
160161 For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation
161162 """
163+ warn ('This method is deprecated and will be removed in upcomming updates, Instead use latest_api()' , DeprecationWarning , stacklevel = 2 )
162164 params = {
163165 'apikey' :self .apikey ,'q' :q ,'qInTitle' :qInTitle ,'country' :country ,'category' :category ,'language' :language ,'domain' :domain ,'timeframe' :str (timeframe ) if timeframe else timeframe ,
164166 'size' :size ,'domainurl' :domainurl ,'excludedomain' :excludedomain ,'timezone' :timezone ,'full_content' :full_content ,'image' :image ,'video' :video ,'prioritydomain' :prioritydomain ,
@@ -173,7 +175,35 @@ def news_api(
173175 if scroll == True :
174176 return self .__get_feeds_all (url = f'{ constants .LATEST_URL } ?{ URL_parameters_encoded } ' ,max_result = max_result )
175177 else :
176- return self .__get_feeds (url = f'{ constants .LATEST_URL } ?{ URL_parameters_encoded } ' )
178+ return self .__get_feeds (url = f'{ constants .LATEST_URL } ?{ URL_parameters_encoded } ' )
179+
180+ def latest_api (
181+ self , q :Optional [str ]= None , qInTitle :Optional [str ]= None , country :Optional [Union [str , list ]]= None , category :Optional [Union [str , list ]]= None ,
182+ language :Optional [Union [str , list ]]= None , domain :Optional [Union [str , list ]]= None , timeframe :Optional [Union [int ,str ]]= None , size :Optional [int ]= None ,
183+ domainurl :Optional [Union [str , list ]]= None , excludedomain :Optional [Union [str , list ]]= None , timezone :Optional [str ]= None , full_content :Optional [bool ]= None ,
184+ image :Optional [bool ]= None , video :Optional [bool ]= None , prioritydomain :Optional [str ]= None , page :Optional [str ]= None , scroll :Optional [bool ]= False ,
185+ max_result :Optional [int ]= None , qInMeta :Optional [str ]= None , tag :Optional [Union [str ,list ]]= None , sentiment :Optional [str ]= None ,
186+ region :Optional [Union [str ,list ]]= None ,excludefield :Optional [Union [str ,list ]]= None
187+ )-> dict :
188+ """
189+ Sending GET request to the latest api.
190+ For more information about parameters and input, Please visit our documentation page: https://newsdata.io/documentation
191+ """
192+ params = {
193+ 'apikey' :self .apikey ,'q' :q ,'qInTitle' :qInTitle ,'country' :country ,'category' :category ,'language' :language ,'domain' :domain ,'timeframe' :str (timeframe ) if timeframe else timeframe ,
194+ 'size' :size ,'domainurl' :domainurl ,'excludedomain' :excludedomain ,'timezone' :timezone ,'full_content' :full_content ,'image' :image ,'video' :video ,'prioritydomain' :prioritydomain ,
195+ 'page' :page ,'qInMeta' :qInMeta ,'tag' :tag , 'sentiment' :sentiment , 'region' :region ,'excludefield' :excludefield
196+ }
197+ URL_parameters = {}
198+ for key ,value in params .items ():
199+ if value is not None :
200+ URL_parameters .update (self .__validate_parms (param = key ,value = value ))
201+
202+ URL_parameters_encoded = urlencode (URL_parameters , quote_via = quote )
203+ if scroll == True :
204+ return self .__get_feeds_all (url = f'{ constants .LATEST_URL } ?{ URL_parameters_encoded } ' ,max_result = max_result )
205+ else :
206+ return self .__get_feeds (url = f'{ constants .LATEST_URL } ?{ URL_parameters_encoded } ' )
177207
178208 def archive_api (
179209 self , q :Optional [str ]= None , qInTitle :Optional [str ]= None , country :Optional [Union [str , list ]]= None , category :Optional [Union [str , list ]]= None ,
0 commit comments