<commit_before>from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand

from share.tasks import BotTask
from share.models import ShareUser
from share.bot import BotAppConfig


class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('--all', action='store_true', help='Run all harvester')
        parser.add_argument('bot', nargs='*', type=str, help='The name of the bot to run')
        parser.add_argument('--last-run', type=int, help='The timestmap of the last run')
        parser.add_argument('--async', action='store_true', help='Whether or not to use Celery')

    def handle(self, *args, **options):
        user = ShareUser.objects.get(username=settings.APPLICATION_USERNAME)

        if not options['bot'] and options['all']:
            options['bot'] = [x.label for x in apps.get_app_configs() if isinstance(x, BotAppConfig)]

        for bot in options['bot']:
            apps.get_app_config(bot)  # Die if the AppConfig can not be loaded

            task_args = (bot, user.id,)
            task_kwargs = {'last_run': options['last_run']}

            if options['async']:
                BotTask().apply_async(task_args, task_kwargs)
                self.stdout.write('Started job for bot {}'.format(bot))
            else:
                self.stdout.write('Running bot for {}'.format(bot))
                BotTask().apply(task_args, task_kwargs, throw=True)
<commit_msg>Correct runbot task_args order<commit_after>from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand

from share.tasks import BotTask
from share.models import ShareUser
from share.bot import BotAppConfig


class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('--all', action='store_true', help='Run all harvester')
        parser.add_argument('bot', nargs='*', type=str, help='The name of the bot to run')
        parser.add_argument('--last-run', type=int, help='The timestmap of the last run')
        parser.add_argument('--async', action='store_true', help='Whether or not to use Celery')

    def handle(self, *args, **options):
        user = ShareUser.objects.get(username=settings.APPLICATION_USERNAME)

        if not options['bot'] and options['all']:
            options['bot'] = [x.label for x in apps.get_app_configs() if isinstance(x, BotAppConfig)]

        for bot in options['bot']:
            apps.get_app_config(bot)  # Die if the AppConfig can not be loaded

            task_args = (user.id, bot, )
            task_kwargs = {'last_run': options['last_run']}

            if options['async']:
                BotTask().apply_async(task_args, task_kwargs)
                self.stdout.write('Started job for bot {}'.format(bot))
            else:
                self.stdout.write('Running bot for {}'.format(bot))
                BotTask().apply(task_args, task_kwargs, throw=True)

{'fraction_non_alphanumeric': 0.12265415549597855, 'fraction_numerical': 0.0, 'mean_word_length': 3.061224489795918, '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': '1768205', 'n_tokens_mistral': 868, 'n_tokens_neox': 837, 'n_words': 235}