import pupa.scrape

from legistar.utils.itemgenerator import make_item
from legistar.ext.pupa.base import Adapter, Converter


class OrgsAdapter(Adapter):
    '''Converts legistar data into a pupa.scrape.Person instance.
    Note the make_item methods are popping values out the dict,
    because the associated keys aren't valid pupa.scrape.Person fields.
    '''
    pupa_model = pupa.scrape.Organization
    aliases = []
    extras_keys = ['meeting_location', 'num_members', 'num_vacancies']

    @make_item('classification')
    def get_classn(self):
        legistar_type = self.data.pop('type')
        return self.config.get_org_classification(legistar_type)


class OrgsConverter(Converter):
    '''Invokes the person and membership adapters to output pupa Person
    objects.
    '''
    adapter = OrgsAdapter

    def gen_agenda_items(self):
        yield from self.make_child(AgendaItemConverter, self.agenda)

    def __iter__(self):
        self.agenda = self.data.pop('agenda', [])
        yield self.get_adapter().get_instance()
        yield from self.gen_agenda_items()

import pupa.scrape

from legistar.utils.itemgenerator import make_item
from legistar.ext.pupa.base import Adapter, Converter


class OrgsAdapter(Adapter):
    '''Converts legistar data into a pupa.scrape.Person instance.
    Note the make_item methods are popping values out the dict,
    because the associated keys aren't valid pupa.scrape.Person fields.
    '''
    pupa_model = pupa.scrape.Organization
    aliases = []
    extras_keys = [
        'meeting_location', 'num_members', 'num_vacancies', 'type']

    @make_item('classification')
    def get_classn(self):
        legistar_type = self.data.pop('type')
        return self.config.get_org_classification(legistar_type)

    def get_instance(self, **extra_instance_data):

        instance_data = self.get_instance_data()
        instance_data.update(extra_instance_data)

        extras = instance_data.pop('extras')
        sources = instance_data.pop('sources')
        identifiers = instance_data.pop('identifiers')

        instance = self.pupa_model(**instance_data)
        instance.extras.update(extras)
        for source in sources:
            instance.add_source(**source)
        for identifier in identifiers:
            instance.add_identifier(**identifier)

        return instance


class OrgsConverter(Converter):
    '''Invokes the person and membership adapters to output pupa Person
    objects.
    '''
    adapter = OrgsAdapter

Remove cruft copied from Memberships adapter
Remove cruft copied from Memberships adapter

  import pupa.scrape
  
  from legistar.utils.itemgenerator import make_item
  from legistar.ext.pupa.base import Adapter, Converter
  
  
  class OrgsAdapter(Adapter):
      '''Converts legistar data into a pupa.scrape.Person instance.
      Note the make_item methods are popping values out the dict,
      because the associated keys aren't valid pupa.scrape.Person fields.
      '''
      pupa_model = pupa.scrape.Organization
      aliases = []
+     extras_keys = [
-     extras_keys = ['meeting_location', 'num_members', 'num_vacancies']
+         'meeting_location', 'num_members', 'num_vacancies', 'type']
  
      @make_item('classification')
      def get_classn(self):
          legistar_type = self.data.pop('type')
          return self.config.get_org_classification(legistar_type)
+ 
+     def get_instance(self, **extra_instance_data):
+ 
+         instance_data = self.get_instance_data()
+         instance_data.update(extra_instance_data)
+ 
+         extras = instance_data.pop('extras')
+         sources = instance_data.pop('sources')
+         identifiers = instance_data.pop('identifiers')
+ 
+         instance = self.pupa_model(**instance_data)
+         instance.extras.update(extras)
+         for source in sources:
+             instance.add_source(**source)
+         for identifier in identifiers:
+             instance.add_identifier(**identifier)
+ 
+         return instance
  
  
  class OrgsConverter(Converter):
      '''Invokes the person and membership adapters to output pupa Person
      objects.
      '''
      adapter = OrgsAdapter
  
-     def gen_agenda_items(self):
-         yield from self.make_child(AgendaItemConverter, self.agenda)
- 
-     def __iter__(self):
-         self.agenda = self.data.pop('agenda', [])
-         yield self.get_adapter().get_instance()
-         yield from self.gen_agenda_items()
- 
Remove cruft copied from Memberships adapter
## Code Before:
import pupa.scrape

from legistar.utils.itemgenerator import make_item
from legistar.ext.pupa.base import Adapter, Converter


class OrgsAdapter(Adapter):
    '''Converts legistar data into a pupa.scrape.Person instance.
    Note the make_item methods are popping values out the dict,
    because the associated keys aren't valid pupa.scrape.Person fields.
    '''
    pupa_model = pupa.scrape.Organization
    aliases = []
    extras_keys = ['meeting_location', 'num_members', 'num_vacancies']

    @make_item('classification')
    def get_classn(self):
        legistar_type = self.data.pop('type')
        return self.config.get_org_classification(legistar_type)


class OrgsConverter(Converter):
    '''Invokes the person and membership adapters to output pupa Person
    objects.
    '''
    adapter = OrgsAdapter

    def gen_agenda_items(self):
        yield from self.make_child(AgendaItemConverter, self.agenda)

    def __iter__(self):
        self.agenda = self.data.pop('agenda', [])
        yield self.get_adapter().get_instance()
        yield from self.gen_agenda_items()

## Instruction:
Remove cruft copied from Memberships adapter
## Code After:
import pupa.scrape

from legistar.utils.itemgenerator import make_item
from legistar.ext.pupa.base import Adapter, Converter


class OrgsAdapter(Adapter):
    '''Converts legistar data into a pupa.scrape.Person instance.
    Note the make_item methods are popping values out the dict,
    because the associated keys aren't valid pupa.scrape.Person fields.
    '''
    pupa_model = pupa.scrape.Organization
    aliases = []
    extras_keys = [
        'meeting_location', 'num_members', 'num_vacancies', 'type']

    @make_item('classification')
    def get_classn(self):
        legistar_type = self.data.pop('type')
        return self.config.get_org_classification(legistar_type)

    def get_instance(self, **extra_instance_data):

        instance_data = self.get_instance_data()
        instance_data.update(extra_instance_data)

        extras = instance_data.pop('extras')
        sources = instance_data.pop('sources')
        identifiers = instance_data.pop('identifiers')

        instance = self.pupa_model(**instance_data)
        instance.extras.update(extras)
        for source in sources:
            instance.add_source(**source)
        for identifier in identifiers:
            instance.add_identifier(**identifier)

        return instance


class OrgsConverter(Converter):
    '''Invokes the person and membership adapters to output pupa Person
    objects.
    '''
    adapter = OrgsAdapter
