-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement NEWS based API support for realtime NEWS and updates
Related to #4 Add NEWS API support for real-time news and updates. * **Configuration Changes** - Add `NEWS_API_KEY` and `NEWS_API_ENDPOINT` to `.env` file. - Update `config/api_config.py` to include `news_api_key` and `news_api_endpoint`. - Add `news_headers` method to `APIConfig` class. - Add `get_news_endpoint` method to `APIConfig` class. * **News Data Fetcher** - Create `data/news_data_fetcher.py` with `NewsDataFetcher` class. - Add `fetch_news_data` method to `NewsDataFetcher` class. * **Main Integration** - Import `NewsDataFetcher` in `main.py`. - Initialize `NewsDataFetcher` instance with `news_api_key` and `news_api_endpoint`. - Update `process_market_data` function to include `news_fetcher` parameter. - Fetch and process news data in `process_market_data` function. * **Data Fetcher Updates** - Import `NewsDataFetcher` in `data/data_fetcher.py`. - Add `news_fetcher` attribute to `DataFetcher` class. - Initialize `news_fetcher` in `DataFetcher` constructor. - Add `fetch_and_process_news_data` method to `DataFetcher` class.
- Loading branch information
1 parent
c241bca
commit 9eaf313
Showing
5 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import requests | ||
import logging | ||
|
||
class NewsDataFetcher: | ||
""" | ||
Fetches news data from the News API. | ||
""" | ||
|
||
def __init__(self, api_key: str, api_endpoint: str): | ||
""" | ||
Initialize the NewsDataFetcher with API key and endpoint. | ||
Args: | ||
api_key: API key for the News API | ||
api_endpoint: Endpoint URL for the News API | ||
""" | ||
self.api_key = api_key | ||
self.api_endpoint = api_endpoint | ||
self.logger = logging.getLogger(__name__) | ||
|
||
def fetch_news_data(self, topic: str) -> dict: | ||
""" | ||
Fetch news data for a given topic. | ||
Args: | ||
topic: Topic for which to fetch news data | ||
Returns: | ||
Dictionary containing news data | ||
""" | ||
try: | ||
self.logger.info(f"Fetching news data for topic: {topic}") | ||
response = requests.get( | ||
self.api_endpoint, | ||
params={"q": topic, "apiKey": self.api_key} | ||
) | ||
response.raise_for_status() | ||
news_data = response.json() | ||
self.logger.info(f"News data fetched successfully for topic: {topic}") | ||
return news_data | ||
except requests.RequestException as e: | ||
self.logger.error(f"Error fetching news data: {str(e)}") | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters