|
@@ -5,7 +5,7 @@ from django.utils import timezone
|
|
from django.db.models import Max
|
|
from django.db.models import Max
|
|
|
|
|
|
from .models import YelpReview, YelpLocation
|
|
from .models import YelpReview, YelpLocation
|
|
-from .scrapper import scrape_reviews_using_browser
|
|
|
|
|
|
+from .scrapper import scrape_reviews
|
|
|
|
|
|
|
|
|
|
def date_string2timezone(date):
|
|
def date_string2timezone(date):
|
|
@@ -41,12 +41,14 @@ def store_into_database(reviews, location):
|
|
)
|
|
)
|
|
if created:
|
|
if created:
|
|
print(f'A new review object has been created for {location}!')
|
|
print(f'A new review object has been created for {location}!')
|
|
|
|
+ else:
|
|
|
|
+ print(f'Review already exist')
|
|
|
|
|
|
|
|
|
|
def populate_yelp_reviews():
|
|
def populate_yelp_reviews():
|
|
yelp_locations = YelpLocation.objects.all()
|
|
yelp_locations = YelpLocation.objects.all()
|
|
for yl in yelp_locations:
|
|
for yl in yelp_locations:
|
|
- reviews = scrape_reviews_using_browser(location_url=yl.url)
|
|
|
|
|
|
+ reviews = scrape_reviews(location_url=yl.url, n_pages=2)
|
|
store_into_database(reviews, yl)
|
|
store_into_database(reviews, yl)
|
|
# pause for 30-60 sec to make request more human-like.
|
|
# pause for 30-60 sec to make request more human-like.
|
|
sleep(random.randint(30, 60))
|
|
sleep(random.randint(30, 60))
|