<commit_before>import logging

from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connection
from raven import Client

from ....tasks import enqueue
from ...models import UniqueFeed, Feed
from ...tasks import update_feed
from ...utils import FeedUpdater

logger = logging.getLogger('feedupdater')


class Command(BaseCommand):
    """Updates the users' feeds"""

    def handle(self, *args, **kwargs):
        if args:
            pk = args[0]
            feed = UniqueFeed.objects.get(pk=pk)
            return update_feed(feed.url, use_etags=False)

        # This command is run every 5 minutes. Don't queue more than
        # 5/45 = a ninth of the total number of feeds.
        limit = UniqueFeed.objects.count() / 9

        uniques = UniqueFeed.objects.filter(
            muted=False,
        ).order_by('last_update')[:limit]

        for unique in uniques:
            try:
                if unique.should_update():
                    enqueue(update_feed, unique.url, timeout=20)
            except Exception:  # We don't know what to expect, and anyway
                               # we're reporting the exception
                if settings.DEBUG or not hasattr(settings, 'SENTRY_DSN'):
                    raise
                else:
                    client = Client(dsn=settings.SENTRY_DSN)
                    client.captureException()
        connection.close()
<commit_msg>Fixed pyflakes<commit_after>import logging

from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connection
from raven import Client

from ....tasks import enqueue
from ...models import UniqueFeed
from ...tasks import update_feed

logger = logging.getLogger('feedupdater')


class Command(BaseCommand):
    """Updates the users' feeds"""

    def handle(self, *args, **kwargs):
        if args:
            pk = args[0]
            feed = UniqueFeed.objects.get(pk=pk)
            return update_feed(feed.url, use_etags=False)

        # This command is run every 5 minutes. Don't queue more than
        # 5/45 = a ninth of the total number of feeds.
        limit = UniqueFeed.objects.count() / 9

        uniques = UniqueFeed.objects.filter(
            muted=False,
        ).order_by('last_update')[:limit]

        for unique in uniques:
            try:
                if unique.should_update():
                    enqueue(update_feed, unique.url, timeout=20)
            except Exception:  # We don't know what to expect, and anyway
                               # we're reporting the exception
                if settings.DEBUG or not hasattr(settings, 'SENTRY_DSN'):
                    raise
                else:
                    client = Client(dsn=settings.SENTRY_DSN)
                    client.captureException()
        connection.close()

{'fraction_non_alphanumeric': 0.08641114982578398, 'fraction_numerical': 0.005574912891986063, 'mean_word_length': 2.0031380753138075, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5518679', 'n_tokens_mistral': 786, 'n_tokens_neox': 728, 'n_words': 234}