|
|
|
@ -292,7 +292,15 @@ class TimeBot: |
|
|
|
|
""" |
|
|
|
|
self.mobatime_api.save_entry(punch_datetime, PunchCodes.BREAK_END.value, note="pause ende").raise_for_status() |
|
|
|
|
|
|
|
|
|
def smart_punch(self, punch_datetime) -> None: |
|
|
|
|
def smart_punch(self, punch_datetime: datetime.datetime) -> None: |
|
|
|
|
""" |
|
|
|
|
Perform smart punch for today. |
|
|
|
|
|
|
|
|
|
This tries to detect your last action and will create entries in to following order: |
|
|
|
|
punch_in -> break_start -> break_end -> punch_out |
|
|
|
|
|
|
|
|
|
:param datetime.datetime punch_datetime: a datetime object to identify the current day aka. today |
|
|
|
|
""" |
|
|
|
|
last_punch = self.mobatime_api.get_entries( |
|
|
|
|
1, |
|
|
|
|
start_date=punch_datetime.replace(hour=0, minute=0, second=0, microsecond=0), |
|
|
|
@ -302,16 +310,16 @@ class TimeBot: |
|
|
|
|
if not last_punch or last_punch[0]["entryNumber"] is None: |
|
|
|
|
self.logger.debug("could not detect any time entry for today... punching in") |
|
|
|
|
method = "punch_in" |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.COMING: |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.COMING.value: |
|
|
|
|
self.logger.debug("your last entry was `punch_in`... starting break") |
|
|
|
|
method = "break_start" |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.BREAK_START: |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.BREAK_START.value: |
|
|
|
|
self.logger.debug("your last entry was `break_start`... ending break") |
|
|
|
|
method = "break_end" |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.BREAK_END: |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.BREAK_END.value: |
|
|
|
|
self.logger.debug("your last entry was `break_end`... punching out") |
|
|
|
|
method = "punch_out" |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.LEAVING: |
|
|
|
|
elif last_punch[0]["entryNumber"] == PunchCodes.LEAVING.value: |
|
|
|
|
self.logger.error("your last entry was `punch_out`... punching in again with this command is not supported") |
|
|
|
|
sys.exit(1) |
|
|
|
|
if method is None: |
|
|
|
@ -320,12 +328,18 @@ class TimeBot: |
|
|
|
|
exit(1) |
|
|
|
|
self.logger.info("running `{}` with date `{}` and time `{}`".format( |
|
|
|
|
method, |
|
|
|
|
punch_datetime.strftime(DateFormats.SIMPLE_DATE), |
|
|
|
|
punch_datetime.strftime(DateFormats.SIMPLE_TIME), |
|
|
|
|
punch_datetime.strftime(DateFormats.SIMPLE_DATE.value), |
|
|
|
|
punch_datetime.strftime(DateFormats.SIMPLE_TIME.value), |
|
|
|
|
)) |
|
|
|
|
getattr(self, method)(punch_datetime) |
|
|
|
|
|
|
|
|
|
def status(self) -> str: |
|
|
|
|
""" |
|
|
|
|
Get and format Mobatime tracking data and and account information. |
|
|
|
|
The output ist formatted to print it to the console. |
|
|
|
|
|
|
|
|
|
:return: preformatted status text |
|
|
|
|
""" |
|
|
|
|
tracking_data = self.mobatime_api.get_tracking_data() |
|
|
|
|
account_info = self.mobatime_api.get_account_information() |
|
|
|
|
ret = "Tracking Info:\n" |
|
|
|
@ -338,11 +352,16 @@ class TimeBot: |
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
def get_hours_present(self) -> datetime.timedelta: |
|
|
|
|
""" |
|
|
|
|
Calculate today's hours present. |
|
|
|
|
|
|
|
|
|
:return: timedelta object with today's hours present |
|
|
|
|
""" |
|
|
|
|
now = datetime.datetime.now() |
|
|
|
|
punches = self.mobatime_api.get_entries( |
|
|
|
|
None, |
|
|
|
|
start_date=now.replace(hour=0, minute=0, second=0, microsecond=0), |
|
|
|
|
end_date=now.replace(hour=0, minute=0, second=0, microsecond=0), |
|
|
|
|
) |
|
|
|
|
time_delta = now - datetime.datetime.strptime(punches[0]["dateTime"], DateFormats.FULL_DATETIME.value) |
|
|
|
|
time_delta = now - datetime.datetime.strptime(punches[-1]["dateTime"], DateFormats.FULL_DATETIME.value) |
|
|
|
|
return time_delta |
|
|
|
|