데이터 최신화 목적 코드


def get_latest_id(place_id: str):
    # place_id로 place의 최신 리뷰 id를 가져오는 함수
    latest_id = "66169f8181314cf26aa9c765"

    return latest_id

while True:
    RESTRAUNT_ID = "1074002248"
    if total_loop_count <= now_loop_count:
        break
    data = dict(
        operationName="getVisitorReviews",
        query="query getVisitorReviews($input: VisitorReviewsInput) { visitorReviews(input: $input) { items { id rating author { id nickname from imageUrl objectId url review { totalCount imageCount avgRating __typename } theme { totalCount __typename } __typename } body thumbnail media { type thumbnail class __typename } tags status visitCount viewCount visited created reply { editUrl body editedBy created replyTitle __typename } originType item { name code options __typename } language highlightOffsets apolloCacheId translatedText businessName showBookingItemName showBookingItemOptions bookingItemName bookingItemOptions votedKeywords { code iconUrl iconCode displayName __typename } userIdno isFollowing followerCount followRequested loginIdno __typename } starDistribution { score count __typename } hideProductSelectBox total showRecommendationSort __typename } }",
        variables=dict(
            id=RESTRAUNT_ID,
            input={
                "bookingBusinessId": "null",
                "businessId": RESTRAUNT_ID,
                "businessType": "restaurant",
                "cidList": ["220036", "220038", "220089", "1000404"],
                "display": 20,
                "getAuthorInfo": True,
                "includeContent": True,
                "includeReceiptPhotos": True,
                "isPhotoUsed": False,
                "item": "0",
                "sort": "recent",
                "page": now_loop_count + 1,
            },
        ),
    )
    resp = requests.post(
        "<https://pcmap-api.place.naver.com/place/graphql>", headers=headers, json=data
    )
    data = resp.json()
    items = data["data"]["visitorReviews"]["items"]

    data_list = []
    for item in items:
    #### 여기서 탈출
        if item["id"] == get_latest_id(RESTRAUNT_ID):
            break
    ####
        keywords = ", ".join([kw["displayName"] for kw in item["votedKeywords"]])
        data_list.append(
            {
                "id": item["id"],
                "body": item["body"],
                "visitCount": item["visitCount"],
                "visited": item["visited"],
                "created": item["created"],
                "votedKeywords": keywords,
            }
        )

    df = pd.DataFrame(data_list)

    print(df)

    break