background_job.py 947 B

12345678910111213141516171819202122232425
  1. import requests
  2. from django.conf import settings
  3. from gauth.models import Location
  4. from analytics.send_email import send_email
  5. from yelp.store_reviews import populate_reviews
  6. to = getattr(settings, 'ADMIN_MAINTEINER_EMAILS')
  7. host_url = getattr(settings, 'HOST_URI')
  8. def send_email_weekly_summary():
  9. # locations = Location.objects.all()
  10. locations = Location.objects.filter(location_id='14748677429039074158')
  11. for location in locations:
  12. to.append(location.recipient_email) if location.recipient_email else None
  13. subject = f"Weekly report for {location.care_name}."
  14. url = f'{host_url}/analytics/weekly-report/{location.location_id}'
  15. message_body = requests.get(url).text
  16. message_body += '<br><p>Regards,</p><p>Byte Trek Team</p>'
  17. send_email(to_list=to, subject=subject, message=message_body)
  18. def background_task_7_days_interval():
  19. populate_reviews()
  20. send_email_weekly_summary()