pip install newsapi
# Import pandas and numpy
import pandas as pd
import numpy as np
# Import NewsAPI module
from newsapi import NewsApiClient
import warnings
warnings.simplefilter('ignore')
pip install --upgrade pandas==1.4.4
# Initialize NewsApiClient with your API key
newsapi = NewsApiClient(api_key='cb48d6540a114e188549d4b21ce36630')
keywords = ['Apple-Stock', 'Apple-Revenue', 'Apple-Sales', 'Apple', 'AAPL']
# Dataframe to store the news article information
article_info = pd.DataFrame(columns=['Date', 'Title', 'Articles', 'Link'])
# Fetch news articles for each keyword
for keyword in keywords:
# Fetch news articles using News API
articles = newsapi.get_everything(q=keyword, language='en', sort_by='publishedAt', page_size=100)
# Extract article details and append to the DataFrame
for article in articles['articles']:
date = pd.to_datetime(article['publishedAt'])
title = article['title']
articles = article['description']
link = article['url']
article_info = article_info.append({'Date': date, 'Title': title,
'Articles': articles, 'Link': link}, ignore_index=True)
# Resetting the index of the final result
article_info.index = pd.RangeIndex(start=1, stop=len(article_info) + 1, step=1)
article_info.tail()
WHEN USING THE ABOVE CODE on my machine, I am not returning an output at all, even though i am not getting any errors. Please could you help me with this? I am attaching an image as well...