Skip to main content

纽约时报文章搜索 API 的 Python 包装器

项目描述

NYTimesArticleAPI是纽约时报文章搜索 API的全功能 Python 包装器。

安装

用点子:

$ pip install NYTimesArticleAPI

依赖项

NYTimesArticleAPI 需要 `requests < https://pypi.python.org/pypi/requests >`__ 和 `setuptools < https://pypi.python.org/pypi/setuptools >`__ 包。

用法

只需使用您的开发人员密钥导入和初始化 API:

>>> from NYTimesArticleAPI import articleAPI
>>> api = articleAPI("YourAPIKey")

然后使用所需的搜索参数/值调用搜索函数:

>>> articles = api.search(q="Obama",
                          fq={"headline": "Obama",
                              "source": ["Reuters",
                                         "AP",
                                         "The New York Times"]},
                          begin_date="20161023", # this can also be an int
                          facet_field=["source", "day_of_week"],
                          facet_filter=True)

搜索函数返回搜索结果的 Python 字典。

您可以使用字典指定多个过滤器:

.. code:: python
>>> fq = {"headline": "Obama", "source": ["Reuters", "AP", "The New York Times"]}

以及使用列表的多个值:

.. code:: python
>>> facet_field = ["source", "day_of_week"]

更多示例:

>>> articles = api.search(q="Obama")

>>> articles = api.search(q="Obama", begin_date="20111231", page=2)

有关可用搜索参数的完整概述,请参阅NYTimes 文章搜索 API 文档

历史

这个包最初由Evan Sherlock编写为 `nytimesarticle < https://github.com/evansherlock/nytimesarticle >`__。此后,它由Matt Morrison分叉和更新,随后发布为 `NyTimesArticleAPI < https://pypi.python.org/pypi/NYTimesArticleAPI >`__,由Gerald SpencerAndrew Han贡献。

执照

© 2016 马特·莫里森mattdmo @ pigimal com

这是免费软件。它是根据MIT License获得许可的。随意在您自己的工作中使用它。但是,如果您修改和/或重新分发它,请以某种方式归于我,并在此或类似许可下分发您的作品。大喊大叫或啤酒将不胜感激。

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

NYTimesArticleAPInew-1.0.0.tar.gz (5.6 kB 查看哈希

已上传 source