store_reviews.py 551 B

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