@@ -0,0 +1,1916 @@
+import sys%0A%0Afrom candidates.popit import PopItApiMixin, popit_unwrap_pagination%0Afrom candidates.update import fix_dates%0A%0Afrom django.core.management.base import BaseCommand%0A%0Afrom slumber.exceptions import HttpClientError%0A%0A%0Adef strip_bogus_fields(data, bogus_field_keys):%0A    for key in bogus_field_keys:%0A        if key in data:%0A            print %22Stripping out%22, key%0A            del data%5Bkey%5D%0A%0A%0Aclass Command(PopItApiMixin, BaseCommand):%0A%0A    def handle(self, **options):%0A        for person in popit_unwrap_pagination(%0A                self.api.persons,%0A                embed='',%0A                per_page=100%0A        ):%0A            msg = %22Person %7B0%7Dpersons/%7B1%7D%22%0A            print msg.format(self.get_base_url(), person%5B'id'%5D)%0A            strip_bogus_fields(%0A                person,%0A                %5B%0A                    'founding_date',%0A                    'dissolution_date',%0A                    'start_date',%0A                    'end_date'%0A                %5D%0A            )%0A            for image in person.get('images', %5B%5D):%0A                image.pop('_id', None)%0A                # Some images have an empty 'created' field, which%0A                # causes an Elasticsearch indexing error, so remove%0A                # that if it's the case:%0A                if not image.get('created'):%0A                    image.pop('created', None)%0A                strip_bogus_fields(%0A                    image,%0A                    %5B%0A                        'birth_date',%0A                        'death_date',%0A                        'founding_date',%0A                        'dissolution_date',%0A                        'start_date',%0A                        'end_date'%0A                    %5D%0A                )%0A            fix_dates(person)%0A            try:%0A                self.api.persons(person%5B'id'%5D).put(person)%0A            except HttpClientError as e:%0A                print %22HttpClientError%22, e.content%0A                sys.exit(1)%0A

Add a command to remove some bogus data key / value pairs