如何按餐厅等级对餐厅名称列表进行排序(可能来自Google Places或Yelp Fusion API)

时间:2019-03-23 20:06:41

标签: csv sorting google-places-api yelp-fusion-api

我有一个csv文件,其中包含成千上万个餐厅名称和地址,我需要按等级(不在csv中的数据)进行排序。有没有办法用此数据填充csv?可能使用Google Places API或Yelp Fusion API?

1 个答案:

答案 0 :(得分:0)

如果使用商家名称和地址进行查询,则Google Places API和Yelp Fusion API均可让您获得餐厅的评分。我将解释如何执行此操作,但首先要注意合规性。您描述的内容显然违反了两个API的服务条款。唯一允许使用其数据的方法是将其显示在公共网站或应用程序上。显然,将其获取并保留在csv文件中是不正确的。这些API用于实时查询并为用户立即显示结果。

Google要求将地方信息数据与Google地图或经批准的“由Google提供支持”图片一起显示。此外,不允许“内容的预取,缓存或存储”。有关详细信息,请参见https://developers.google.com/places/web-service/policies

Yelp需要注明出处,基本上要求您显示星级和Yelp徽标,并提供指向Yelp上您所查询餐厅业务页面的链接。请参见https://www.yelp.com/developers/display_requirements。此外,自收到Yelp内容起二十四(24)小时内,您不能“缓存,记录,预取或以其他方式存储Yelp内容的任何部分,或者尝试或提供执行任何抓取或“批量下载”操作的方法。”有关全文和术语,请参见https://www.yelp.com/developers/api_terms

在不使用法律术语的情况下,以下是从Google地方信息中请求餐厅评分的方法:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Applebees,234 W 42nd St,New York,NY&inputtype=textquery&fields=formatted_address,name,rating&key=YOUR_API_KEY

并且,JSON响应:

{
    "candidates": [
        {
            "formatted_address": "234 W 42nd St, New York, NY 10036, USA",
            "name": "Applebee's Grill + Bar",
            "rating": 3.6
        }
    ],
    "status": "OK"
}

这是对Yelp Fusion的相同请求。没有办法只要求评级。结果始终包含餐馆数据库中的所有内容:

https://api.yelp.com/v3/businesses/search?term=applebees&location=234 W 42nd St,New York,NY&limit=1

JSON响应:

{
    "businesses": [
        {
            "id": "gytFjzBw-z5LZD-6JSMChg",
            "alias": "applebees-grill-bar-new-york-3",
            "name": "Applebee's Grill + Bar",
            "image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/CLizyj9S7pMvwGNm2dgdiQ/o.jpg",
            "is_closed": false,
            "url": "https://www.yelp.com/biz/applebees-grill-bar-new-york-3?adjust_creative=pnOv3Zj2REsNDMU4Z3-SLg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=pnOv3Zj2REsNDMU4Z3-SLg",
            "review_count": 444,
            "categories": [
                {
                    "alias": "tradamerican",
                    "title": "American (Traditional)"
                },
                {
                    "alias": "burgers",
                    "title": "Burgers"
                },
                {
                    "alias": "sportsbars",
                    "title": "Sports Bars"
                }
            ],
            "rating": 2,
            "coordinates": {
                "latitude": 40.756442,
                "longitude": -73.988838
            },
            "transactions": [
                "delivery",
                "pickup"
            ],
            "price": "$$",
            "location": {
                "address1": "234 W 42nd St",
                "address2": "",
                "address3": "",
                "city": "New York",
                "zip_code": "10036",
                "country": "US",
                "state": "NY",
                "display_address": [
                    "234 W 42nd St",
                    "New York, NY 10036"
                ]
            },
            "phone": "+12123917414",
            "display_phone": "(212) 391-7414",
            "distance": 5.938732504864397
        }
    ],
    "total": 2900,
    "region": {
        "center": {
            "longitude": -73.98880004882812,
            "latitude": 40.75648701137637
        }
    }
}