|
@@ -82,7 +82,7 @@ def insert_review_into_database(unrecorded_reviews, loc):
|
|
review.save()
|
|
review.save()
|
|
|
|
|
|
|
|
|
|
-def fetch_all_review(loc_id):
|
|
|
|
|
|
+def sync_all_review(loc_id):
|
|
loc = Location.objects.get(pk=loc_id)
|
|
loc = Location.objects.get(pk=loc_id)
|
|
max_date = get_max_date(loc_id)
|
|
max_date = get_max_date(loc_id)
|
|
next_page_token = ''
|
|
next_page_token = ''
|
|
@@ -103,6 +103,32 @@ def fetch_all_review(loc_id):
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
+def update_location_data(loc, average_rating, total_reviews, total_reviews_db):
|
|
|
|
+ loc.average_rating = average_rating
|
|
|
|
+ loc.total_review = total_reviews
|
|
|
|
+ loc.total_review_DB = total_reviews_db
|
|
|
|
+ loc.save()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def fetch_all_review(loc_id):
|
|
|
|
+ loc = Location.objects.get(pk=loc_id)
|
|
|
|
+ max_date = get_max_date(loc_id)
|
|
|
|
+ headers = get_auth_header()
|
|
|
|
+ url = get_review_list_url(loc_id)
|
|
|
|
+ res = get(url, headers=headers)
|
|
|
|
+ if res.status_code == 401:
|
|
|
|
+ return
|
|
|
|
+ data = res.json()
|
|
|
|
+ reviews = data['reviews']
|
|
|
|
+ average_rating = data.get('averageRating')
|
|
|
|
+ total_reviews = data.get('totalReviewCount')
|
|
|
|
+ unrecorded_reviews = filter_unrecorded_review_by_date(reviews, max_date)
|
|
|
|
+ if len(unrecorded_reviews) != 0:
|
|
|
|
+ insert_review_into_database(unrecorded_reviews, loc)
|
|
|
|
+ total_reviews_db = Review.objects.filter(location_id=loc_id).count()
|
|
|
|
+ update_location_data(loc, average_rating, total_reviews, total_reviews_db)
|
|
|
|
+
|
|
|
|
+
|
|
def populate_reviews():
|
|
def populate_reviews():
|
|
start = timezone.now()
|
|
start = timezone.now()
|
|
locations = get_all_location_ids()
|
|
locations = get_all_location_ids()
|