store_reviews.py 648 B

12345678910111213141516171819202122232425
  1. import requests
  2. from django.conf import settings
  3. from .scrapper import scrape_reviews
  4. from .utils import get_max_date, store_into_database
  5. from .models import YelpLocation
  6. BROWSER_URI = getattr(settings, 'BROWSER_URI')
  7. def store_yelp_reviews(location, n_pages):
  8. location_url = location.url
  9. max_date = get_max_date(location)
  10. reviews = scrape_reviews(
  11. location_url=location_url,
  12. max_date=max_date,
  13. n_pages=n_pages
  14. )
  15. if reviews:
  16. store_into_database(reviews, location)
  17. def populate_reviews():
  18. locations = YelpLocation.objects.all()
  19. for yl in locations:
  20. store_yelp_reviews(yl, 1)