import main.share as share
import logging as log
from main.bemo import Bemo
from main.mail.mail import Mail
from datetime import date, datetime
from main.timez import TimeZ
class Attendance(TimeZ):

  def __init__(self):
      self.bemo = Bemo()
      self.mail = Mail()

  # Doing attendance
  def attend(self, force_run=False):
    today = date.today() #datetime.strptime('20210729', "%Y%m%d").date()
    attendance_today = {}
    late_time = 0.0
    # Load attendance list
    attendances = self.bemo.load_attendance()
    if attendances:
      # Look for each record to find the today's attendance
      records = attendances['result']['records']
      for i in range(0, len(records)):
        record = records[i]
        check_in = self.convert_tz(record['check_in'])
        check_out = self.convert_tz(record['check_out'])
        if check_in.date() == today:
          attendance_today = record
        elif check_in.month == today.month and check_in.year == today.year:
          late_time += record['hours_arrive_late'] + record['hours_leave_soon']
      
      attendance = {}
      # If today's attendance exists then execute checkout
      if attendance_today:
        if force_run or self.__is_out_working_time():
          log.info('Check out')
          attendance = self.bemo.attendance_manual()
          check_in = self.convert_tz(attendance['check_in'])
          check_out = self.convert_tz(attendance['check_out'])
          log.info(f'CI: {check_in}; CO: {check_out}')
        else:
          log.info('Please wait until the end of business hours')
      # Otherwise doing checkin
      else:
        log.info('Check in')
        attendance = self.bemo.attendance_manual()
        check_in = self.convert_tz(attendance['check_in'])
        check_out = self.convert_tz(attendance['check_out'])
        log.info(f'CI: {check_in}; CO: {check_out}')

      # Send email
      self.mail.send(attendance, late_time)

  # Check out working time
  def __is_out_working_time(self):
    end_date_time = datetime.strptime(share.config['working-time']['afternoon']['end'], "%H:%M").time()
    return datetime.now().time() > end_date_time

3460ad0ceb49a7bef519b95d082b533d9596f5c3
<mask token>


class Attendance(TimeZ):
    <mask token>
    <mask token>

    def __is_out_working_time(self):
        end_date_time = datetime.strptime(share.config['working-time'][
            'afternoon']['end'], '%H:%M').time()
        return datetime.now().time() > end_date_time

<mask token>


class Attendance(TimeZ):

    def __init__(self):
        self.bemo = Bemo()
        self.mail = Mail()
    <mask token>

    def __is_out_working_time(self):
        end_date_time = datetime.strptime(share.config['working-time'][
            'afternoon']['end'], '%H:%M').time()
        return datetime.now().time() > end_date_time

<mask token>


class Attendance(TimeZ):

    def __init__(self):
        self.bemo = Bemo()
        self.mail = Mail()

    def attend(self, force_run=False):
        today = date.today()
        attendance_today = {}
        late_time = 0.0
        attendances = self.bemo.load_attendance()
        if attendances:
            records = attendances['result']['records']
            for i in range(0, len(records)):
                record = records[i]
                check_in = self.convert_tz(record['check_in'])
                check_out = self.convert_tz(record['check_out'])
                if check_in.date() == today:
                    attendance_today = record
                elif check_in.month == today.month and check_in.year == today.year:
                    late_time += record['hours_arrive_late'] + record[
                        'hours_leave_soon']
            attendance = {}
            if attendance_today:
                if force_run or self.__is_out_working_time():
                    log.info('Check out')
                    attendance = self.bemo.attendance_manual()
                    check_in = self.convert_tz(attendance['check_in'])
                    check_out = self.convert_tz(attendance['check_out'])
                    log.info(f'CI: {check_in}; CO: {check_out}')
                else:
                    log.info('Please wait until the end of business hours')
            else:
                log.info('Check in')
                attendance = self.bemo.attendance_manual()
                check_in = self.convert_tz(attendance['check_in'])
                check_out = self.convert_tz(attendance['check_out'])
                log.info(f'CI: {check_in}; CO: {check_out}')
            self.mail.send(attendance, late_time)

    def __is_out_working_time(self):
        end_date_time = datetime.strptime(share.config['working-time'][
            'afternoon']['end'], '%H:%M').time()
        return datetime.now().time() > end_date_time

import main.share as share
import logging as log
from main.bemo import Bemo
from main.mail.mail import Mail
from datetime import date, datetime
from main.timez import TimeZ


class Attendance(TimeZ):

    def __init__(self):
        self.bemo = Bemo()
        self.mail = Mail()

    def attend(self, force_run=False):
        today = date.today()
        attendance_today = {}
        late_time = 0.0
        attendances = self.bemo.load_attendance()
        if attendances:
            records = attendances['result']['records']
            for i in range(0, len(records)):
                record = records[i]
                check_in = self.convert_tz(record['check_in'])
                check_out = self.convert_tz(record['check_out'])
                if check_in.date() == today:
                    attendance_today = record
                elif check_in.month == today.month and check_in.year == today.year:
                    late_time += record['hours_arrive_late'] + record[
                        'hours_leave_soon']
            attendance = {}
            if attendance_today:
                if force_run or self.__is_out_working_time():
                    log.info('Check out')
                    attendance = self.bemo.attendance_manual()
                    check_in = self.convert_tz(attendance['check_in'])
                    check_out = self.convert_tz(attendance['check_out'])
                    log.info(f'CI: {check_in}; CO: {check_out}')
                else:
                    log.info('Please wait until the end of business hours')
            else:
                log.info('Check in')
                attendance = self.bemo.attendance_manual()
                check_in = self.convert_tz(attendance['check_in'])
                check_out = self.convert_tz(attendance['check_out'])
                log.info(f'CI: {check_in}; CO: {check_out}')
            self.mail.send(attendance, late_time)

    def __is_out_working_time(self):
        end_date_time = datetime.strptime(share.config['working-time'][
            'afternoon']['end'], '%H:%M').time()
        return datetime.now().time() > end_date_time

import main.share as share
import logging as log
from main.bemo import Bemo
from main.mail.mail import Mail
from datetime import date, datetime
from main.timez import TimeZ
class Attendance(TimeZ):

  def __init__(self):
      self.bemo = Bemo()
      self.mail = Mail()

  # Doing attendance
  def attend(self, force_run=False):
    today = date.today() #datetime.strptime('20210729', "%Y%m%d").date()
    attendance_today = {}
    late_time = 0.0
    # Load attendance list
    attendances = self.bemo.load_attendance()
    if attendances:
      # Look for each record to find the today's attendance
      records = attendances['result']['records']
      for i in range(0, len(records)):
        record = records[i]
        check_in = self.convert_tz(record['check_in'])
        check_out = self.convert_tz(record['check_out'])
        if check_in.date() == today:
          attendance_today = record
        elif check_in.month == today.month and check_in.year == today.year:
          late_time += record['hours_arrive_late'] + record['hours_leave_soon']
      
      attendance = {}
      # If today's attendance exists then execute checkout
      if attendance_today:
        if force_run or self.__is_out_working_time():
          log.info('Check out')
          attendance = self.bemo.attendance_manual()
          check_in = self.convert_tz(attendance['check_in'])
          check_out = self.convert_tz(attendance['check_out'])
          log.info(f'CI: {check_in}; CO: {check_out}')
        else:
          log.info('Please wait until the end of business hours')
      # Otherwise doing checkin
      else:
        log.info('Check in')
        attendance = self.bemo.attendance_manual()
        check_in = self.convert_tz(attendance['check_in'])
        check_out = self.convert_tz(attendance['check_out'])
        log.info(f'CI: {check_in}; CO: {check_out}')

      # Send email
      self.mail.send(attendance, late_time)

  # Check out working time
  def __is_out_working_time(self):
    end_date_time = datetime.strptime(share.config['working-time']['afternoon']['end'], "%H:%M").time()
    return datetime.now().time() > end_date_time
