added date parameter
This commit is contained in:
@@ -11,6 +11,7 @@ import sys
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
import datetime as dt
|
||||
|
||||
from newsapi import NewsApiClient
|
||||
from dotenv import load_dotenv
|
||||
@@ -25,15 +26,16 @@ sources = source_json["sources"]
|
||||
str_sources = ",".join([source["id"] for source in sources])
|
||||
|
||||
|
||||
def get_all_news_by_keyword(keyword, from_date="2022-01-01", to_date="2022-03-29"): # hard coded will change soon
|
||||
def get_all_news_by_keyword(keyword, from_date="2000-01-01"): # hard coded will change soon
|
||||
"""get all news to keyword
|
||||
Args:
|
||||
keyword (String): keyword for search
|
||||
from_date (String): min date for search
|
||||
|
||||
Returns:
|
||||
JSON/dict: dict containing articles
|
||||
"""
|
||||
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en')
|
||||
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date)
|
||||
return top_headlines
|
||||
|
||||
def format_article(article):
|
||||
@@ -54,7 +56,8 @@ def format_article(article):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
print("fetching top news by keyword business...")
|
||||
print("this is a module and should not be run directly")
|
||||
print("fetching top news by keyword bitcoin...")
|
||||
|
||||
articles = get_all_news_by_keyword("bitcoin")
|
||||
formatted_article = format_article(articles["articles"][0])
|
||||
|
Reference in New Issue
Block a user