mattlisiv / newsapi-python

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

Set default language as en #18

Closed gabrieldespindula closed 5 years ago

gabrieldespindula commented 5 years ago

Hey guys, I'm using the module to create a headline display, using some dot displays, thanks for your efforts on this code, I liked it a lot!

Now regarding my suggestion, What about setting the default language to en, this way we can use newsapi.get_top_headlines() only, without any arguments. Currently if we do so it raises an exception.

I can send a pull request to implement it if you want.

mattlisiv commented 5 years ago

Hi @gabrieldespindula ,

I do not believe the language option is an available parameter for the top headlines endpoint. What is the current error you are receiving?

Thanks, Matt

gabrieldespindula commented 5 years ago

Hey there, I tested and it does work in some different languages. My point is just a small improvement. Currently if you run: from newsapi import NewsApiClient newsapi = NewsApiClient(api_key='your key') top_headlines = newsapi.get_top_headlines()

you get this exception:

Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\newsapi\newsapi_client.py", line 119, in get_top_headlines raise NewsAPIException(r.json()) newsapi.newsapi_exception.NewsAPIException

but if you send top_headlines = newsapi.get_top_headlines(language='en') It works just fine. My suggestion is set 'en' as default language instead of 'None'. Look at newsapi_client.py line 12

Then would be possible to request the headlines without any argument. English language will be the default when sending the API. And it also prevent new users from receiving this exception.

mattlisiv commented 5 years ago

Ok great. I think something may have changed, because this error is new. Either way, I think that is a great idea to default the language.

A PR would be fantastic, or I'll get around to updating it later this week.

Thanks!

mattlisiv commented 5 years ago

Corrected with pull request https://github.com/mattlisiv/newsapi-python/pull/25 .