from django.core.management.base import BaseCommand

from core.rss import sync_active_sources


class Command(BaseCommand):
    help = "Import active RSS feeds into newsroom articles"

    def add_arguments(self, parser):
        parser.add_argument('--limit', type=int, default=8, help='Number of feed items per source')
        parser.add_argument('--stale-minutes', type=int, default=0, help='Only sync sources older than this many minutes')

    def handle(self, *args, **options):
        created = sync_active_sources(limit=options['limit'], stale_minutes=options['stale_minutes'])
        self.stdout.write(self.style.SUCCESS(f'Imported {created} article(s).'))
