rL i?bddlmZddlZddlmZddlmZddlmZddl m Z m Z Gdde Z y) )unicode_literalsN)const) NewsApiAuth)NewsAPIException)is_valid_stringstringify_date_paramcHeZdZdZddZ ddZ d dZd dZy) NewsApiClientaThe core client object used to fetch data from News API endpoints. :param api_key: Your API key, a length-32 UUID string provided for your News API account. You must `register `_ for a News API key. :type api_key: str :param session: An optional :class:`requests.Session` instance from which to execute requests. **Note**: If you provide a ``session`` instance, :class:`NewsApiClient` will *not* close the session for you. Remember to call ``session.close()``, or use the session as a context manager, to close the socket and free up resources. :type session: `requests.Session `_ or None NcPt||_| t|_y||_y)N)api_key)rauthrequestsrequest_method)selfr sessions \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/newsapi/newsapi_client.py__init__zNewsApiClient.__init__s#0 ?"*D ")D c Fi} |t|r|| d<n td|t|r|| d<n td||| td|t|r|| d<n td|9t|r#|tjvr|| d<ntd td |9t|r#|tj vr|| d <ntd td |9t|r#|tj vr|| d<ntdtd|Ft|tk(r)d|cxkrdkrn td|| d<ntdtd|3t|tk(r|dkDr|| d<ntdtd|jjtj|jd| } | jtjj k7rt#| j%| j%S)a Call the `/top-headlines` endpoint. Fetch live top and breaking headlines. This endpoint provides live top and breaking headlines for a country, specific category in a country, single source, or multiple sources. You can also search with keywords. Articles are sorted by the earliest date published first. :param q: Keywords or a phrase to search for in the article title and body. See the official News API `documentation `_ for search syntax and examples. :type q: str or None :param qintitle: Keywords or a phrase to search for in the article title and body. See the official News API `documentation `_ for search syntax and examples. :type q: str or None :param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from. Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the `sources index `_. **Note**: you can't mix this param with the ``country`` or ``category`` params. :type sources: str or None :param language: The 2-letter ISO-639-1 code of the language you want to get headlines for. See :data:`newsapi.const.languages` for the set of allowed values. The default for this method is ``"en"`` (English). **Note**: this parameter is not mentioned in the `/top-headlines documentation `_ as of Sep. 2019, but *is* supported by the API. :type language: str or None :param country: The 2-letter ISO 3166-1 code of the country you want to get headlines for. See :data:`newsapi.const.countries` for the set of allowed values. **Note**: you can't mix this parameter with the ``sources`` param. :type country: str or None :param category: The category you want to get headlines for. See :data:`newsapi.const.categories` for the set of allowed values. **Note**: you can't mix this parameter with the ``sources`` param. :type category: str or None :param page_size: Use this to page through the results if the total results found is greater than the page size. :type page_size: int or None :param page: The number of results to return per page (request). 20 is the default, 100 is the maximum. :type page: int or None :return: JSON response as nested Python dictionary. :rtype: dict :raises NewsAPIException: If the ``"status"`` value of the response is ``"error"`` rather than ``"ok"``. q,keyword/phrase q param should be of type strqintitle3keyword/phrase qintitle param should be of type strz5cannot mix country/category param with sources param.sources#sources param should be of type strlanguageinvalid language$language param should be of type strcountryinvalid country#country param should be of type strcategoryinvalid category$category param should be of type strrdpageSize2page_size param should be an int between 1 and 100 page_size param should be an intpage*page param should be an int greater than 0page param should be an intr timeoutparams)r TypeError ValueErrorr languages countries categoriestypeintrgetTOP_HEADLINES_URLr status_codercodesokrjson) rrrrrrr" page_sizer)payloadrs rget_top_headlineszNewsApiClient.get_top_headlines sDn =q!   NOO  x(&. # UVV  w':@TTU U  w'%, " EFF  x(u.*2GJ'$%788 FGG  w'eoo-)0GI&$%677 EFF  x(u///*2GJ'$%788 FGG  I#% (S(%%YZZ+4GJ'$%YZZ BCC  DzS !8&*GFO$%QRR =>>    # #E$;$;$))UW`g # h ==HNN-- -"1668, ,vvxrc pi} |t|r|| d<n td|t|r|| d<n td|t|r|| d<n td|t|r|| d<n td|!t|tr|| d <n td |t || d <|t || d <|9t|r#|t j vr td || d<n td| 9t| r#| t jvr| | d<ntdtd| Ft| tk(r)d| cxkrdkrn td| | d<ntdtd| 3t| tk(r| dkDr| | d<ntdtd|jjt j|jd| } | jt j"j$k7rt'| j)| j)S)a| Call the `/everything` endpoint. Search through millions of articles from over 30,000 large and small news sources and blogs. :param q: Keywords or a phrase to search for in the article title and body. See the official News API `documentation `_ for search syntax and examples. :type q: str or None :param qintitle: Keywords or a phrase to search for in the article title and body. See the official News API `documentation `_ for search syntax and examples. :type q: str or None :param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from. Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the `sources index `_. :type sources: str or None :param domains: A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to. :type domains: str or None :param exclude_domains: A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results. :type exclude_domains: str or None :param from_param: A date and optional time for the oldest article allowed. If a str, the format must conform to ISO-8601 specifically as one of either ``%Y-%m-%d`` (e.g. *2019-09-07*) or ``%Y-%m-%dT%H:%M:%S`` (e.g. *2019-09-07T13:04:15*). An int or float is assumed to represent a Unix timestamp. All datetime inputs are assumed to be UTC. :type from_param: str or datetime.datetime or datetime.date or int or float or None :param to: A date and optional time for the newest article allowed. If a str, the format must conform to ISO-8601 specifically as one of either ``%Y-%m-%d`` (e.g. *2019-09-07*) or ``%Y-%m-%dT%H:%M:%S`` (e.g. *2019-09-07T13:04:15*). An int or float is assumed to represent a Unix timestamp. All datetime inputs are assumed to be UTC. :type to: str or datetime.datetime or datetime.date or int or float or None :param language: The 2-letter ISO-639-1 code of the language you want to get headlines for. See :data:`newsapi.const.languages` for the set of allowed values. :type language: str or None :param sort_by: The order to sort articles in. See :data:`newsapi.const.sort_method` for the set of allowed values. :type sort_by: str or None :param page: The number of results to return per page (request). 20 is the default, 100 is the maximum. :type page: int or None :param page_size: Use this to page through the results if the total results found is greater than the page size. :type page_size: int or None :return: JSON response as nested Python dictionary. :rtype: dict :raises NewsAPIException: If the ``"status"`` value of the response is ``"error"`` rather than ``"ok"``. rrrrrrdomainsz#domains param should be of type strexcludeDomainsz+exclude_domains param should be of type strfromtorrrsortByz invalid sortz#sort_by param should be of type strrr%r&r'r(r)r*r+r,r-)rr0 isinstancestrrrr2r1 sort_methodr5r6rr7EVERYTHING_URLr r9rr:r;rr<)rrrrrBexclude_domains from_paramrErsort_byr)r=r>r?s rget_everythingzNewsApiClient.get_everythings_P =q!   NOO  x(&. # UVV  w'%, " EFF  w'%, " EFF  &/3/,;() MNN  !2:>GFO >04GDM  x(5??2$%788*2GJ' FGG  w'e///(/GH%$^44 EFF  I#% (S(%%YZZ+4GJ'$%YZZ BCC  DzS !8&*GFO$%QRR =>>    # #E$8$8tyyRT]d # e ==HNN-- -"1668, ,vvxrcvi}|9t|r#|tjvr||d<ntdt d|9t|r#|tj vr||d<ntdt d|9t|r#|tj vr||d<ntdt d |jjtj|jd | }|jtjjk7rt|j!|j!S) aCall the `/sources` endpoint. Fetch the subset of news publishers that /top-headlines are available from. :param category: Find sources that display news of this category. See :data:`newsapi.const.categories` for the set of allowed values. :type category: str or None :param language: Find sources that display news in a specific language. See :data:`newsapi.const.languages` for the set of allowed values. :type language: str or None :param country: Find sources that display news in a specific country. See :data:`newsapi.const.countries` for the set of allowed values. :type country: str or None :return: JSON response as nested Python dictionary. :rtype: dict :raises NewsAPIException: If the ``"status"`` value of the response is ``"error"`` rather than ``"ok"``. rrrrr r!r"r#r$r,r-)rrr2r1r0r3r4rr7 SOURCES_URLr r9rr:r;rr<)rr"rrr>r?s r get_sourceszNewsApiClient.get_sourcesRs%,  x(u.*2GJ'$%788 FGG  w'eoo-)0GI&$%677 EFF  x(u///*2GJ'$%788 FGG    # #E$5$5DIIrZa # b ==HNN-- -"1668, ,vvxr)N)NNNenNNNN) NNNNNNNNNNN)NNN)__name__ __module__ __qualname____doc__rr@rNrQrrr r sI *uyK^   cJ=rr ) __future__rrnewsapirnewsapi.newsapi_authrnewsapi.newsapi_exceptionr newsapi.utilsrrobjectr rWrrr^s%',6?DFDr