background_job.py 778 B

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