<commit_before>from datetime import datetime

from django.core.management.base import BaseCommand

from couchdbkit import ResourceConflict

from mygpo.core import models
from mygpo.api.models import Podcast
from mygpo.utils import progress
from mygpo.decorators import repeat_on_conflict


class Command(BaseCommand):

    def handle(self, *args, **options):

        started = datetime.now()
        entries = models.Podcast.view('core/podcasts_by_oldid').iterator()
        total = models.Podcast.view('core/podcasts_by_oldid', limit=1).total_rows

        for n, entry in enumerate(entries):
            self.update(entry=entry, started=started)
            progress(n, total)


    @repeat_on_conflict('entry')
    def update(self, entry, started):
        try:
            p = Podcast.objects.get(id=entry.oldid)
        except Podcast.DoesNotExist:
            return

        data = models.SubscriberData(
            timestamp        = started,
            subscriber_count = max(0, p.subscriber_count()),
            )
        entry.subscribers.append(data)
        entry.save()<commit_msg>reflect change to @repeat_on_conflict in update-toplist<commit_after>from datetime import datetime

from django.core.management.base import BaseCommand

from couchdbkit import ResourceConflict

from mygpo.core import models
from mygpo.api.models import Podcast
from mygpo.utils import progress
from mygpo.decorators import repeat_on_conflict


class Command(BaseCommand):

    def handle(self, *args, **options):

        started = datetime.now()
        entries = models.Podcast.view('core/podcasts_by_oldid').iterator()
        total = models.Podcast.view('core/podcasts_by_oldid', limit=1).total_rows

        for n, entry in enumerate(entries):
            self.update(entry=entry, started=started)
            progress(n, total)


    @repeat_on_conflict(['entry'])
    def update(self, entry, started):
        try:
            p = Podcast.objects.get(id=entry.oldid)
        except Podcast.DoesNotExist:
            return

        data = models.SubscriberData(
            timestamp        = started,
            subscriber_count = max(0, p.subscriber_count()),
            )
        entry.subscribers.append(data)
        entry.save()
{'fraction_non_alphanumeric': 0.0927743086529884, 'fraction_numerical': 0.001784121320249777, 'mean_word_length': 2.8211243611584327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491022', 'n_tokens_mistral': 655, 'n_tokens_neox': 630, 'n_words': 144}