Ejemplo n.º 1
0
def resolve_place(partial_place=None, partial_location=None):
    '''
    Resolves a partial Place or Location object into a complete Place 
    using the Factual Resolve API. Returns None if resolution was not 
    possible.
    '''
    if partial_place:
        loc = partial_place.location
        pl_name = partial_place.name
    else:
        loc = partial_location
        pl_name = None

    try:
        if loc is None:
            resp = factual_client.resolve(name=pl_name)
        else:
            resp = factual_client.resolve(name=pl_name,
                                          address=loc.address,
                                          town=loc.town,
                                          state=loc.state,
                                          postcode=loc.postcode,
                                          latitude=loc.latitude,
                                          longitude=loc.longitude)
    except FactualAPIError:
        return None

    result = resp.get_resolved_result()
    if result:
        return _resolve_result_to_place(result)
    else:
        return None
Ejemplo n.º 2
0
def resolve_place(partial_place=None,partial_location=None):
    '''
    Resolves a partial Place or Location object into a complete Place 
    using the Factual Resolve API. Returns None if resolution was not 
    possible.
    '''
    if partial_place:
        loc = partial_place.location
        pl_name = partial_place.name
    else:
        loc = partial_location
        pl_name = None

    try:
        if loc is None:
            resp = factual_client.resolve(name=pl_name)
        else:
            resp = factual_client.resolve(
                name=pl_name,
                address=loc.address,
                town=loc.town,
                state=loc.state,
                postcode=loc.postcode,
                latitude=loc.latitude,
                longitude=loc.longitude)
    except FactualAPIError:
        return None

    result = resp.get_resolved_result()
    if result:
        return _resolve_result_to_place(result)
    else:
        return None
Ejemplo n.º 3
0
    def test_successful_request(self):
        '''
        Tests response from a few Resolve API calls known to work
        '''
        # tests almost complete entry
        result = factual_client.resolve(
            name='primanti brothers',
            town='pittsburgh',
            state='PA',
            latitude=40.45,
            longitude=-79.98).get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'], 'Primanti Brothers')
        self.assertEquals(result['postcode'], '15222')

        # tests simple one with incomplete name
        result = factual_client.resolve(name='otb',
                                        town='pittsburgh',
                                        state='pa').get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'], 'OTB Bicycle Cafe')
        self.assertEquals(result['postcode'], '15203')

        # tests one that requires a more specific town to work
        result = factual_client.resolve(name='petco',
                                        town='monroeville',
                                        state='pa').get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'], 'Petco')
        self.assertEquals(result['postcode'], '15146')
Ejemplo n.º 4
0
    def test_unsuccessful_request(self):
        '''
        Tests response from a few Resolve API calls known to not work
        '''

        # tests a totally out there response
        result = factual_client.resolve(name='primanti brothers',town='San Diego',state='CA').get_resolved_result()
        self.assertIsNone(result)

        # tests one too ambiguous to resolve
        result = factual_client.resolve(name='primanti brothers',town='pittsburgh',state='PA').get_resolved_result()
        self.assertIsNone(result)
Ejemplo n.º 5
0
    def test_unsuccessful_request(self):
        '''
        Tests response from a few Resolve API calls known to not work
        '''

        # tests a totally out there response
        result = factual_client.resolve(name='primanti brothers',
                                        town='San Diego',
                                        state='CA').get_resolved_result()
        self.assertIsNone(result)

        # tests one too ambiguous to resolve
        result = factual_client.resolve(name='primanti brothers',
                                        town='pittsburgh',
                                        state='PA').get_resolved_result()
        self.assertIsNone(result)
Ejemplo n.º 6
0
    def test_successful_request(self):
        '''
        Tests response from a few Resolve API calls known to work
        '''
        # tests almost complete entry
        result = factual_client.resolve(name='primanti brothers',
                                            town='pittsburgh',state='PA',
                                            latitude=40.45,longitude=-79.98).get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'],'Primanti Brothers')
        self.assertEquals(result['postcode'],'15222')


        # tests simple one with incomplete name
        result = factual_client.resolve(name='otb',town='pittsburgh',state='pa').get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'],'OTB Bicycle Cafe')
        self.assertEquals(result['postcode'],'15203')

        # tests one that requires a more specific town to work
        result = factual_client.resolve(name='petco',town='monroeville',state='pa').get_resolved_result()
        self.assertIsNotNone(result)
        self.assertEquals(result['name'],'Petco')
        self.assertEquals(result['postcode'],'15146')