Пример #1
0
def find_nearby_city_configs(latlng):
    if not latlng:
        return []
    city_configs = []
    for city_config in GUIDES_BY_CITY.itervalues():
        distance = geometry.earth_distance_meters(
            city_config.latlng['lat'], city_config.latlng['lng'],
            latlng.lat, latlng.lng)
        if distance < 40000:
            city_configs.append(city_config)
    return city_configs
def main():
    db_user = user.User.get_by_email(GUIDE_USER)
    all_trip_plans_for_user = data.load_all_trip_plans_for_creator(db_user.id)

    outfile = cStringIO.StringIO()
    writer = csv.writer(outfile)
    writer.writerow([
        'name',
        'location_name',
        'source host',
        'source_url',
        'trip plan url',
        'admin url',

        'missing_location_name',
        'missing_location_latlng',
        'missing_cover_image',

        'num_entities',
        'num_missing_name',
        'num_missing_photos',
        'num_missing_location',
        'num_weird_location',
        'num_missing_category',
        'num_missing_description',
        ])


    for trip_plan in all_trip_plans_for_user:
        if not trip_plan.source_url:
            continue
        source_host = urlparse.urlparse(trip_plan.source_url).netloc.lower()

        num_missing_name = 0
        num_missing_photos = 0
        num_missing_location = 0
        num_weird_location = 0
        num_missing_category = 0
        num_missing_description = 0
        for e in trip_plan.entities:
            if not e.name:
                num_missing_name += 1
            if not e.photo_urls:
                num_missing_photos += 1
            if not e.latlng:
                num_missing_location += 1
            elif trip_plan.location_latlng:
                distance_from_guide_center = geometry.earth_distance_meters(
                    trip_plan.location_latlng.lat, trip_plan.location_latlng.lng,
                    e.latlng.lat, e.latlng.lng)
                if distance_from_guide_center > 10000:
                    num_weird_location += 1
            if not e.category or not e.category.category_id:
                num_missing_category += 1
            if not e.description:
                num_missing_description += 1

        writer.writerow([
            trip_plan.name.encode('utf-8') if trip_plan.name else None,
            trip_plan.location_name.encode('utf-8') if trip_plan.location_name else None,
            source_host,
            trip_plan.source_url.encode('utf-8') if trip_plan.source_url else None,
            '%s/guide/%s' % (constants.BASE_URL, trip_plan.trip_plan_id),
            '%s/admin/editor/%s' % (constants.BASE_URL, trip_plan.trip_plan_id),
            0 if trip_plan.location_name else 1,
            0 if trip_plan.location_latlng else 1,
            0 if trip_plan.cover_image_url else 1,
            len(trip_plan.entities),
            num_missing_name,
            num_missing_photos,
            num_missing_location,
            num_weird_location,
            num_missing_category,
            num_missing_description,
            ])

    print outfile.getvalue()
    outfile.close()