Spaces:
Running
Running
| from typing import List | |
| from news_scraper.adapters.base_adapter import BaseAdapter | |
| class Scraper: | |
| def __init__(self, adapters: List[BaseAdapter], database: None): | |
| self.adapters = adapters | |
| self.database = None | |
| def scrape(self) -> None: | |
| """ | |
| Scrapes articles from all configured news sources and saves them to database | |
| """ | |
| for adapter in self.adapters: | |
| try: | |
| articles = adapter.fetch_articles() | |
| #TODO - Add logic to save articles to database | |
| for article in articles: | |
| adapter.parse_article(article) # For the time being, we will just parse the article and print it | |
| except Exception as e: | |
| print(f"Error with adapter {adapter.__class__.__name__}: {str(e)}") | |
| continue | |
| def add_adapter(self, adapter: BaseAdapter) -> None: | |
| """ | |
| Adds a new news source adapter to the scraper | |
| """ | |
| self.adapters.append(adapter) |