Пример #1
0
def main():
    device_location = { 'lat':10.0, 'lng':5.5 }
    search_center = 'San Francisco, CA'

    api = HearPlanet()
    request = api.table('poi').search().depth('all')
    request = request.location(search_center)
    request = request.point(device_location)

    # limit to citysearch channel
    request = request.filters({'ch':'citysearch'})

    # get the first three pages (10 POI's per page) in three requests
    for page in (1, 2, 3):
        request = request.page(page)
        pois = request.objects()
        for poi in pois:
            # print the poi title and latitude and longitude.
            # distance is in meters, distance_str is formatted per locale.
            print "%s (%s, %s) %s" % (poi.title, poi.lat,
                poi.lng, poi.distance_str)

            # loop over the articles associated with the poi
            # if they have addresses, web sites or phone numbers
            # print them.
            for art in poi.articles:
                print "\t%s" % art.title
                for addr in getattr(art, 'addresses', []):
                    print '\tAddress:', addr.address
                for site in getattr(art, 'websites', []):
                    print '\tWebsite:', site.url
                for phone in getattr(art, 'phones', []):
                        print '\tPhone:', phone.phone
Пример #2
0
def main():
    # Set up the HearPlanet API with valid credentials.
    # They can be set in /etc/hearplanet.cfg or overridden in
    # ~/.hearplanet.cfg
    # ... and create the API object.
    api = HearPlanet()

    # Make a request for POI's located near (the center of) San Francisco
    req = api.table('poi').search().location('San Francisco, CA')

    page_num = 0
    index = 1
    while True:
        page_num += 1
        req = req.page(page_num)
        objects = req.objects()
        for obj in objects:
            _print_obj(index, obj)
            index += 1
        if not req.more():
            break
def main():
    api = HearPlanet()
    articles = api.table('article').featured().depth('article').objects()
    for art in articles:
        print "%s (%s, %s)" % (art.title, art.lat, art.lng)