def process_results(self, results):
        self.log(' Creating and/or updating models...')
        self.log('  Found %s elections.' % len(results))

        # Loop through all the results
        for d in results:

            self.log('  Processing %s' % d['raw_name'])

            election, c = Election.objects.get_or_create(
                year=d['year'],
                election_type=d['election_type'],
                id_raw=d['id'],
                sort_index=d['sort_index']
            )

            if self.verbosity > 2:
                if c:
                    self.log('  Created %s' % election)

            # Loop through the data list from the scraped page
            for office_dict in d['data'].values():

                # Loop through each of the offices we found there
                for office_name, candidates in office_dict.items():

                    # Create an office object out of the data
                    office, c = Office.objects.get_or_create(
                        **self.parse_office_name(office_name)
                    )

                    # Log
                    if self.verbosity > 2:
                        if c:
                            self.log('  Created %s' % office)

                    # Loop through each of the candidates
                    for candidate in candidates:

                        # If it doesn't have an id, skip it.
                        if not candidate['id']:
                            continue
                        # If it does, try to find a matching Filer object
                        # and then add it to the database
                        try:
                            # Pull the Filer object from the database
                            filer = Filer.objects.get(
                                filer_id_raw=int(candidate['id'])
                            )

                            # Get or create the Candidate object
                            candidate, c = Candidate.objects.get_or_create(
                                election=election,
                                office=office,
                                filer=filer
                            )

                            # Log
                            if self.verbosity > 2:
                                if c:
                                    self.log('  Created %s' % candidate)

                        # And if there isn't filer just rock on
                        except Filer.DoesNotExist:
                            pass
dataset/ETHPy150Open california-civic-data-coalition/django-calaccess-campaign-browser/calaccess_campaign_browser/management/commands/scrapecalaccesscampaigncandidates.py/Command.process_results/original