Giter Site home page Giter Site logo

pynyt's Introduction

About

pynyt is a wrapper for the New York Times Article Search API, which enables retrieval of Times article metadata via a variety of query fields. This wrapper makes use of the requests library. pynyt is written in Python 3.

6/3/2019: pynyt has not been updated since 2017 and is probably incompatible with the current version of the Article Search API.

Installation

import sys

sys.path.append('path/to/pynyt'))
from pynyt import NYTArticleAPIObject

Accessing the Article Search API requires an API key, which can be obtained for free here.

Usage

Results are returned as a list of dictionaries, each list representing a page of results (10 articles per page). The API's paginator limits results to 100 pages (or 1000 articles)—set halt_overflow=False to return the first 1000 results even if more exist. Set verbose=True to see search progress (page number) printed to the console.

Documentation of query and result fields can be found here (click 'Show details').

Enter any number of query parameters as keyword arguments:

miner = NYTArticleAPIObject('your API key')

# get 1000 news articles from the Foreign newsdesk from 1987
results_1987 = miner.query(fq = {'source': 'New York Times',
                                 'news_desk': 'Foreign',
                                 'type_of_material': 'News'},
                           begin_date = 19870101,
                           end_date = 19871231,
                           halt_overflow = False)
                           
# get 2017 articles about the Federal Reserve with faceting by news source and day of week
results_obama = miner.query(q = 'Federal Reserve',
                            begin_date = 20170101,
                            facet_field = ['source', 
                                           'day_of_week'],
                            facet_filter = True)

Call get_usage() to get the number of remaining API calls for the day (daily limit of 1000 for a given key; note that pagination consumes API calls).

pynyt's People

Contributors

smalawi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pynyt's Issues

KeyError in line 55

I'm getting a "KeyError: 'response'" message in line 55 of this program. I haven't modified it at all, I just opened it and tried to run it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.