예제 #1
0
def get_district_and_muni(url, entity_list):
    """
    This is the district and muni finder main() .
    it searchs a url from the open-muni API for all results and finds all
    Gis data it can find using these results.

    :param url: the url which is the lookup for all muni's in the open-muni API
    :param entity_list: the entity_list this is mostly here because of the recursive behivior of the function.
    :return: returns a entity dictionary which has all entity's found and all which aren't.
    """
    print url
    data = tools.get_data_as_dict(url)
    next_page = ''
    if data['next']:
        next_page = data['next']
    results_list = data['results']
    for result in results_list:
        if not result['name_en']:
            #TODO add support for results with no english keyword
            continue  # if their is no name in english. i can't store the files for now so continue.
        entity = objects.entity(result)
        if get_entity_polygon(entity):
            entity_list['found'].append(entity)  # if found add to the entity list
        else:
            entity_list['not_found'].append(entity)
    if next_page:
        get_district_and_muni(next_page, entity_list)
    return entity_list
예제 #2
0
    def add_info(self, api_result):

        """
        add info which isn't given directly by the muni - API , we search for the path untill the highest parent and
        add the division name.
        :type api_result: an API result from open muni
        :param api_result: the Api search result for this entity.
        """
        if api_result[PARENT]:
            self.parent_path = tools.get_parent_path('', api_result)

        if api_result[DIVISION]:
            self.division_name = tools.get_data_as_dict(api_result[DIVISION][URL])['name']
            self.division_id = api_result[DIVISION]['id']