Esempio n. 1
0
def accept_place(modeladmin, request, queryset, accept_link=True):
    from places.google_places_helper import fetch_details_for_place_id
    # we listify the queryset since we're going to edit objects such that they won't appear
    # in the queryset anymore
    any_added = False
    for suggestion in list(queryset):
        place_id = suggestion.place_id
        try:
            p = Place.objects.get(place_id=place_id)
        except Place.DoesNotExist:
            any_added = True
            p = Place(place_id=place_id)

            r, photo_url, photo_attrib = fetch_details_for_place_id(place_id)
            if not r.get(
                    'rating'
            ):  # probably not meaningful place, or Google returned NOT_FOUND
                suggestion.processed = True
                suggestion.save()
                continue
            p.name = r['name']
            p.address = r['formatted_address']
            p.image_url = photo_url
            p.user_rating = r['rating']
            p.num_ratings = r['user_ratings_total']
            p.place_types = ','.join(r.get('types', []))
            p.place_url = r.get('website')
            lat, lng = r['geometry']['location']['lat'], r['geometry'][
                'location']['lng']
            p.lat = lat
            p.lng = lng
            p.image_attribution = photo_attrib
        if accept_link:
            p.gift_card_url = check_link_against_blacklist(
                suggestion.gift_card_url) or p.gift_card_url
        p.donation_url = p.donation_url or suggestion.donation_url
        p.email_contact = suggestion.email or p.email_contact
        p.save()
        suggestion.processed = True
        suggestion.save()
    if any_added:
        # Note: this is a fairly expensive operation, but should be ok to run
        # once at the end of an admin action
        Area.update_area_for_all_places()
Esempio n. 2
0
df = pd.read_csv(fl)

for _, row in df.iterrows():
    place_id = row['place_id']
    try:
        p = Place.objects.get(place_id=place_id)
    except Place.DoesNotExist:
        p = Place(place_id=place_id)

        r, photo_url, photo_attrib = fetch_details_for_place_id(place_id)
        if not r.get('rating'):  # probably not meaningful place
            continue
        p.name = r['name']
        p.address = r['formatted_address']
        p.image_url = photo_url
        p.user_rating = r['rating']
        p.num_ratings = r['user_ratings_total']
        p.place_types = ','.join(r.get('types', []))
        p.place_url = r.get('website')
        lat, lng = r['geometry']['location']['lat'], r['geometry']['location']['lng']
        p.lat = lat or row['lat']
        p.lng = lng or row['lng']
        p.image_attribution = photo_attrib
        p.gift_card_url = row.get('gift_card_url','')
        p.takeout_url = row.get('takeout_url','')
        p.donation_url = row.get('donation_url','')
        p.email_contact = row.get('email','')

        p.save()