|
@@ -156,11 +156,28 @@ def fetch_all_review(loc_id):
|
|
|
update_location_data(loc, average_rating, total_reviews, total_reviews_db)
|
|
|
|
|
|
|
|
|
+def fetch_last_50_reviews(loc_id):
|
|
|
+ loc = Location.objects.get(pk=loc_id)
|
|
|
+ headers = get_auth_header()
|
|
|
+ url = get_review_list_url(loc_id)+'&pageSize=50'
|
|
|
+ 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')
|
|
|
+ if reviews.count() > 0:
|
|
|
+ insert_review_into_database(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():
|
|
|
start = timezone.now()
|
|
|
locations = get_all_location_ids()
|
|
|
for loc_id in locations:
|
|
|
- fetch_all_review(loc_id)
|
|
|
+ fetch_last_50_reviews(loc_id)
|
|
|
end = timezone.now()
|
|
|
elapsed = end - start
|
|
|
print(f'Elapsed time: {elapsed.seconds//60} minutes and {elapsed.seconds % 60} secs.')
|