mattlisiv / newsapi-python

A Python Client for News API
MIT License
375 stars 130 forks source link

Best way to track search results by day #65

Closed onseau closed 3 years ago

onseau commented 4 years ago

There's no problem with the code—I just don't know much programming.

So I have a list of terms that I'd like to create timeseries of, by days for about a 5-6 month period.

Hopefully, I can just change the keyword, run the script, and end up with a .csv file with just two or three columns for the date, and the # of results on that day.

Using the Dev version, which is limited to 500 requsts a day. I don't think I can get the actual dates for individual articles if I use a long period of time right? So I guess I'll have to do each day separately.

Can this be done with loops to print the total number of articles per day? And would anyone be willing to help me out (please?)? Would be very much appreciated :)

Thank you!

onseau commented 4 years ago

this is what i have so far:

from newsapi import NewsApiClient import pandas as pd from datetime import date, timedelta newsapi = NewsApiClient(api_key='eb23958504c749a492b172c14a926be3') startDate = date(2020, 5, 7) endDate = date(2020, 5, 9) delta = timedelta(days=1) while startDate <= endDate: try: search_date_df = all_articles = newsapi.get_everything(q='coronavirus', from_param=startDate, to=startDate, language='en',) search_date_df.to_csv(country+'_coronavirus.csv') print(str(startDate) + ' was succesful') startDate += delta except Exception as e: print(str(startDate) + ' failed' + str(e)) break

mattlisiv commented 3 years ago

Hi @onseau ,

Unfortunately, this issue tracker is not meant to assist people with projects, only to resolve issues with the underlying library.

Please look elsewhere for project support.

Best luck!