#!/usr/bin/env python3
"""
Test script to scrape a single 20min.ch article directly.
"""

import sys
import logging
import json
from pathlib import Path
from scraper import TwentyMinScraper

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)

# Example URL with known comments
ARTICLE_URL = "https://www.20min.ch/story/20-laender-trumps-prioritaetenliste-fuer-zollverhandlungen-enthuellt-103339848"

def main():
    """Scrape a single article directly."""
    logger.info(f"Starting direct scrape of: {ARTICLE_URL}")
    
    # Create the data directory
    data_dir = Path("data")
    data_dir.mkdir(exist_ok=True)
    
    # Initialize scraper
    scraper = TwentyMinScraper()
    
    # Extract article data
    article_data = scraper.extract_article_data(ARTICLE_URL)
    
    if article_data:
        logger.info(f"Successfully extracted article: {article_data['title']}")
        logger.info(f"Comment count: {article_data['comment_count']}")
        logger.info(f"Comments extracted: {len(article_data['comments'])}")
        
        # Save the data
        filepath = scraper.save_article_data(article_data)
        logger.info(f"Saved article data to: {filepath}")
        
        # Display the first few comments
        for i, comment in enumerate(article_data['comments'][:3]):
            logger.info(f"Comment {i+1}: Author: {comment['author']}, Content: {comment['content'][:50]}...")
    else:
        logger.error("Failed to extract article data")
    
    logger.info("Direct scrape completed")

if __name__ == "__main__":
    main() 