26 lines
956 B
Python
26 lines
956 B
Python
|
|
from django.core.management.base import BaseCommand
|
||
|
|
from django.utils import timezone
|
||
|
|
|
||
|
|
from feeds.models import Source
|
||
|
|
from feeds.refresh import refresh
|
||
|
|
from podcasts.views import _in_backoff_q
|
||
|
|
|
||
|
|
|
||
|
|
class Command(BaseCommand):
|
||
|
|
help = 'Refresh the feed reader\'s sources (news and blogs)'
|
||
|
|
|
||
|
|
def add_arguments(self, parser):
|
||
|
|
parser.add_argument('--source-id', type=int, help='Refresh only this source (even when backing off)')
|
||
|
|
|
||
|
|
def handle(self, *args, **options):
|
||
|
|
qs = Source.objects.select_related('user').order_by('last_refreshed_at')
|
||
|
|
if options['source_id']:
|
||
|
|
qs = qs.filter(pk=options['source_id'])
|
||
|
|
else:
|
||
|
|
qs = qs.exclude(_in_backoff_q(timezone.now()))
|
||
|
|
if not qs.exists():
|
||
|
|
self.stdout.write('No sources to refresh.')
|
||
|
|
return
|
||
|
|
refreshed, failed, new = refresh(qs)
|
||
|
|
self.stdout.write(f'{refreshed} sources refreshed, {failed} failed, +{new} items')
|