Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article Search API Query Problem #59

Open
hp0404 opened this issue Aug 28, 2021 · 1 comment
Open

Article Search API Query Problem #59

hp0404 opened this issue Aug 28, 2021 · 1 comment

Comments

@hp0404
Copy link

hp0404 commented Aug 28, 2021

Hi there!

I'm trying to use Article Search API to download articles that are relevant to this query:
("military" OR "soldier*" OR "air force" OR "navy" OR "army") AND ("threat*" OR "danger*" OR "fear*" OR "risk*")

But some entries are just random?


The code I used

import requests

apikey = ""

params = {
    "fq": '("military" OR "soldier*" OR "air force" OR "navy" OR "army") AND ("threat*" OR "danger*" OR "fear*" OR "risk*")',
    "begin_date": "20210101",
    "end_date": "20210601",
    "api-key": apikey,
    "page": 0
}
headers = {"Accept": "application/json"}
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json", params=params, headers=headers).json()

for item in response["response"]["docs"]:
    print(item["abstract"])

# What happens to the nearly two million people in our nation’s prison system demonstrates who we are as a people.
# A look back at what has transpired in the year since Mr. Floyd’s murder reveals a country both struggling to confront it history # of racial division and continuing to succumb to it.
# A cease-fire between Israel and Hamas.
# Mr. Biden has spoken publicly about how he once sent Mr. Netanyahu a photograph with the inscription, “Bibi, I don’t agree with a damn thing you say, but I love you.”
# The move, which will require companies to report to the government any significant attacks, is a response to the Colonial Pipeline ransomware attacks.
# Mr. Protasevich, 26, is an exiled dissident whose reach drew an authoritarian ruler into a gambit that outraged Western governments.
# Israeli extremists have formed more than 100 new groups on the Facebook-owned encrypted messaging app in recent days to target attacks.
# A new kind of pandemic grief.
# After 11 days of intense fighting, Hamas and Israel began a cease-fire. Here is the arc of the conflict.
# An eviction in East Jerusalem lies at the center of a conflict that led to war between Israel and Hamas. But for millions of Palestinians, the routine indignities of occupation are part of daily life.
@nyt-hughmandeville
Copy link
Collaborator

The Article Search API searches the article body and some of the metadata fields (headline, byline, ...).

("military" OR "soldier" OR "air force" OR "navy" OR "army") AND ("threat" OR "danger" OR "fear" OR "risk")

I checked a few of the articles that you mentioned and their bodies contain the words in your query.

https://www.nytimes.com/2021/05/31/opinion/covid-new-york-state-prisons.html
has the words soldier, threat, and fear.

https://www.nytimes.com/2021/05/25/us/george-floyd-protests-unrest-events-timeline.html
has the words military, navy, soldier, threatens, fear.

https://www.nytimes.com/2021/05/18/us/politics/biden-netanyahu.html
has the words military, air force, and threat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants