|
@@ -1,4 +1,5 @@
|
|
import re
|
|
import re
|
|
|
|
+import time
|
|
import json
|
|
import json
|
|
from requests import get, put, post
|
|
from requests import get, put, post
|
|
from gauth.auth_utils import get_gmb_id, get_auth_header
|
|
from gauth.auth_utils import get_gmb_id, get_auth_header
|
|
@@ -85,7 +86,7 @@ def insert_review_into_database(reviews, loc_id):
|
|
replied_text=replied_text,
|
|
replied_text=replied_text,
|
|
create_time=create_time
|
|
create_time=create_time
|
|
)
|
|
)
|
|
- review.reply = reply
|
|
|
|
|
|
+ review.reply = reply
|
|
else:
|
|
else:
|
|
review.reply = None
|
|
review.reply = None
|
|
review.save()
|
|
review.save()
|
|
@@ -101,6 +102,7 @@ def sync_all_review(loc_id):
|
|
headers = get_auth_header()
|
|
headers = get_auth_header()
|
|
while True:
|
|
while True:
|
|
url = get_review_list_url(loc_id, next_page_token)
|
|
url = get_review_list_url(loc_id, next_page_token)
|
|
|
|
+ time.sleep(5)
|
|
res = get(url, headers=headers)
|
|
res = get(url, headers=headers)
|
|
if res.status_code == 401:
|
|
if res.status_code == 401:
|
|
headers = get_auth_header()
|
|
headers = get_auth_header()
|
|
@@ -158,7 +160,7 @@ def store_batch_of_reviews(reviews):
|
|
replied_text=replied_text,
|
|
replied_text=replied_text,
|
|
create_time=create_time
|
|
create_time=create_time
|
|
)
|
|
)
|
|
- review.reply = reply
|
|
|
|
|
|
+ review.reply = reply
|
|
else:
|
|
else:
|
|
review.reply = None
|
|
review.reply = None
|
|
review.save()
|
|
review.save()
|
|
@@ -200,7 +202,7 @@ def populate_reviews():
|
|
locations = Location.objects.all().values('location_id')
|
|
locations = Location.objects.all().values('location_id')
|
|
for loc in locations:
|
|
for loc in locations:
|
|
loc_id = loc.get('location_id')
|
|
loc_id = loc.get('location_id')
|
|
- fetch_last_20_reviews(loc_id)
|
|
|
|
|
|
+ sync_all_review(loc_id)
|
|
end = timezone.now()
|
|
end = timezone.now()
|
|
elapsed = end - start
|
|
elapsed = end - start
|
|
print(f'Elapsed time: {elapsed.seconds//60} minutes and {elapsed.seconds % 60} secs.')
|
|
print(f'Elapsed time: {elapsed.seconds//60} minutes and {elapsed.seconds % 60} secs.')
|