def fetch_all_from_api(cls, instance, writeitinstance): """ Get all the documents from the API and save them locally. """ cls = Person data = requests.get(instance.url).json() if 'persons' in data: # Direct Popolo data, list of persons with name/email/image/summary/inline memberships collection_url = instance.url people = data['persons'] for p in people: # XXX IDs in transformed EP have person/ at the front? p['id'] = 'person/%s' % p['id'] p.setdefault('memberships', []).extend([ m for m in data['memberships'] if m['person_id'] == p['id'] ]) else: api_client = instance.api_client(cls.api_collection_name) # This is hacky, but I can't see a documented way to get to the url. # Liable to change if slumber changes their internals. collection_url = api_client._store['base_url'] people = get_paginated_generator(api_client) for doc in people: # Add url to the doc url = collection_url + '/' + doc['id'] doc['popit_url'] = url obj = cls.update_from_api_results(instance=instance, doc=doc) PopitPerson.create_contact(obj, doc, writeitinstance)
def fetch_all_from_api(cls, instance, writeitinstance): """ Get all the documents from the API and save them locally. """ cls = Person data = requests.get(instance.url).json() if 'persons' in data: # Direct Popolo data, list of persons with name/email/image/summary/inline memberships collection_url = instance.url people = data['persons'] for p in people: # XXX IDs in transformed EP have person/ at the front? p['id'] = 'person/%s' % p['id'] p.setdefault('memberships', []).extend( [m for m in data['memberships'] if m['person_id'] == p['id']]) else: api_client = instance.api_client(cls.api_collection_name) # This is hacky, but I can't see a documented way to get to the url. # Liable to change if slumber changes their internals. collection_url = api_client._store['base_url'] people = get_paginated_generator(api_client) for doc in people: # Add url to the doc url = collection_url + '/' + doc['id'] doc['popit_url'] = url obj = cls.update_from_api_results(instance=instance, doc=doc) PopitPerson.create_contact(obj, doc, writeitinstance)
def get_collection(self, collection, fn=None): api_client = self.ai.api_client(collection) objects = list(get_paginated_generator(api_client)) if fn: objects = fn(objects, api_client) objects = dict([ (doc['id'], doc) for doc in objects ]) return objects
def fetch_all_from_api(cls, instance, writeitinstance): """ Get all the documents from the API and save them locally. """ cls = Person api_client = instance.api_client(cls.api_collection_name) # This is hacky, but I can't see a documented way to get to the url. # Liable to change if slumber changes their internals. collection_url = api_client._store['base_url'] for doc in get_paginated_generator(api_client): # Add url to the doc url = collection_url + '/' + doc['id'] doc['popit_url'] = url obj = cls.update_from_api_results(instance=instance, doc=doc) PopitPerson.create_contact(obj, doc, writeitinstance)