text: import sys
  sys.path.append("..")
  from util.utilities import *
  
  logging.basicConfig(
      level=logging.INFO,
      format='%(asctime)s - %(levelname)s - %(message)s',
      datefmt='%B-%d-%Y %H:%M:%S',
      filename=f"../logs/{Path(__file__).stem}.log",
      filemode='w'
  )
  
  def send_daily_attendance_report():
      with open('../html/daily_attendance.html', 'r') as f:
          html_email = f.read()
  
  
      start_date = '2021-08-11'
      today = datetime.datetime.now().strftime('%Y-%m-%d')
      days_in_session = 0
  
      calendar_days = calendar_days = sr_api_pull(
          'calendar-days',
          parameters = {
              'school_ids': 15,
              'min_date': start_date,
              'max_date': today
          }
      )
  
      absences = sr_api_pull(
          'absences',
          parameters = {
              'active': '1',
              'school_ids': 15,
              'min_date': today,
              'max_date': today,
              'expand': 'absence_type, student.grade_level'
          }
      )
  
      students = sr_api_pull(
          'students',
          parameters = {
              'active': 1,
              'school_ids': 15,
              'expand': 'grade_level, student_detail' # student_attrs.student_attr_type
          }
      )
  
      grade_9_count = 0
      grade_10_count = 0
      grade_11_count = 0
      grade_12_count = 0
  
      for student in students:
          if student['grade_level']['order_key'] == '9':
              grade_9_count += 1
          if student['grade_level']['order_key'] == '10':
              grade_10_count += 1
          if student['grade_level']['order_key'] == '11':
              grade_11_count += 1
          if student['grade_level']['order_key'] == '12':
              grade_12_count += 1
  
      # counts up how many days we've completed as of today
      for day in calendar_days:
          if day['in_session'] == '1':
              days_in_session += 1
  
      absence_count_9 = 0
      absence_count_10 = 0
      absence_count_11 = 0
      absence_count_12 = 0
      oss_count = 0
      absence_count_total = 0
  
      absences_9 = ''
      absences_10 = ''
      absences_11 = ''
      absences_12 = ''
      oss_list = ''
  
      for absence in sorted(absences, key=lambda item: item['student']['first_name']):
          if absence['student']['active'] != '0' and absence['absence_type']['in_school'] == '0' and absence['student']['grade_level']['order_key'] == '9':
              absences_9 += f"{absence['student']['first_name']} {absence['student']['last_name']} ({absence['absence_type']['code']})<br>"
              absence_count_9 += 1
              absence_count_total += 1
          if absence['student']['active'] != '0' and absence['absence_type']['in_school'] == '0' and absence['student']['grade_level']['order_key'] == '10':
              absences_10 += f"{absence['student']['first_name']} {absence['student']['last_name']} ({absence['absence_type']['code']})<br>"
              absence_count_10 += 1
              absence_count_total += 1
          if absence['student']['active'] != '0' and absence['absence_type']['in_school'] == '0' and absence['student']['grade_level']['order_key'] == '11':
              absences_11 += f"{absence['student']['first_name']} {absence['student']['last_name']} ({absence['absence_type']['code']})<br>"
              absence_count_11 += 1
              absence_count_total += 1
          if absence['student']['active'] != '0' and absence['absence_type']['in_school'] == '0' and absence['student']['grade_level']['order_key'] == '12':
              absences_12 += f"{absence['student']['first_name']} {absence['student']['last_name']} ({absence['absence_type']['code']})<br>"
              absence_count_12 += 1
              absence_count_total += 1
          if (absence['student']['active'] != '0' and absence['absence_type']['code'] == 'OSS'):
              oss_list += f"<li>{absence['student']['first_name']} {absence['student']['last_name']}</li>"
              oss_count += 1
  
      if oss_count == 0:
          oss_list = '<li>There are no students on OSS today.</li>'
  
      if today_is_a_school_day():
          send_email(
              msg_subject= f"EOD Attendance {round((100 - absence_count_total / (grade_9_count + grade_10_count + grade_11_count + grade_12_count) * 100), 2)}% _ email or text w. corrections",
              html_msg=html_email
                  .replace('###9list###', absences_9)
                  .replace('###10list###', absences_10)
                  .replace('###11list###', absences_11)
                  .replace('###12list###', absences_12)
                  .replace('###oss_list###', oss_list)
                  .replace('###day_count###', str(days_in_session))
                  .replace('###9percentage###', f"{round((100 - (absence_count_9 / grade_9_count * 100)), 2)}%")
                  .replace('###10percentage###', f"{round((100 - (absence_count_10 / grade_10_count * 100)), 2)}%")
                  .replace('###11percentage###', f"{round((100 - (absence_count_11 / grade_11_count * 100)), 2)}%")
                  .replace('###12percentage###', f"{round((100 - (absence_count_12 / grade_12_count * 100)), 2)}%")
                  .replace('###overall###', f"{round((100 - absence_count_total / (grade_9_count + grade_10_count + grade_11_count + grade_12_count) * 100), 2)}%"),
              bcc='team@livingstoncollegiate.org',
              reply_to='cpuliafico@collegiateacademies.org'
          )
      else:
          logging.info('not a school day, no need to send')
  
  if __name__ == '__main__':
      send_daily_attendance_report()