<commit_before>import logging
import itertools

from django.core.management.base import BaseCommand

logger = logging.getLogger(__name__)

class Command(BaseCommand):
    help = 'Pulls new data for all RepresentativeSets from ScraperWiki'

    def handle(self, *args, **options):
        from representatives.models import RepresentativeSet, Election

        for rs in itertools.chain(
                RepresentativeSet.objects.filter(enabled=True), Election.objects.filter(enabled=True)):
            rs.update_from_data_source()
<commit_msg>Slightly better error handling in updaterepresentatives<commit_after>import logging
import itertools

from django.core.management.base import BaseCommand

logger = logging.getLogger(__name__)

class Command(BaseCommand):
    help = 'Pulls new data for all RepresentativeSets from ScraperWiki'

    def handle(self, *args, **options):
        from representatives.models import RepresentativeSet, Election

        for rs in itertools.chain(
                RepresentativeSet.objects.filter(enabled=True), Election.objects.filter(enabled=True)):
            try:
                rs.update_from_data_source()
            except Exception as e:
                logger.exception("Failure updating %r" % rs)
                rs.__class__.objects.filter(pk=rs.pk).update(last_import_successful=False)

{'fraction_non_alphanumeric': 0.08071748878923767, 'fraction_numerical': 0.0, 'mean_word_length': 3.508417508417508, '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': '6270363', 'n_tokens_mistral': 356, 'n_tokens_neox': 338, 'n_words': 89}