|
@@ -83,8 +83,12 @@ def insert_review_into_database(unrecorded_reviews, loc):
|
|
|
|
|
|
|
|
|
def sync_all_review(loc_id):
|
|
|
+ '''
|
|
|
+ Sync a location if any bad thing occur for example any network break.
|
|
|
+ :param: loc_id -> Location id of a particular location
|
|
|
+ :return: None -> It just update all reviews of this location and return nothing.
|
|
|
+ '''
|
|
|
loc = Location.objects.get(pk=loc_id)
|
|
|
- max_date = get_max_date(loc_id)
|
|
|
next_page_token = ''
|
|
|
headers = get_auth_header()
|
|
|
while True:
|
|
@@ -95,12 +99,15 @@ def sync_all_review(loc_id):
|
|
|
continue
|
|
|
data = res.json()
|
|
|
reviews = data['reviews']
|
|
|
- unrecorded_reviews = filter_unrecorded_review_by_date(reviews, max_date)
|
|
|
- if len(unrecorded_reviews) != 0:
|
|
|
- insert_review_into_database(unrecorded_reviews, loc)
|
|
|
+ if len(reviews) != 0:
|
|
|
+ insert_review_into_database(reviews, loc)
|
|
|
next_page_token = data.get('nextPageToken')
|
|
|
if next_page_token is None:
|
|
|
break
|
|
|
+ average_rating = data.get('averageRating')
|
|
|
+ total_reviews = data.get('totalReviewCount')
|
|
|
+ total_reviews_db = Review.objects.filter(location_id=loc_id).count()
|
|
|
+ update_location_data(loc, average_rating, total_reviews, total_reviews_db)
|
|
|
|
|
|
|
|
|
def update_location_data(loc, average_rating, total_reviews, total_reviews_db):
|