(20260110) Attendance-sync'ing ready with a manual attendance script also.
This commit is contained in:
+76
-9
@@ -59,7 +59,7 @@ from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
|
||||
# To work with datatypes:
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Literal
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
@@ -239,9 +239,10 @@ def branch_add(
|
||||
}
|
||||
)
|
||||
|
||||
# # Debugging:
|
||||
# response_json = response.json()
|
||||
# print("TCAOFF Branch-Add:", json.to_string(response_json))
|
||||
# Debugging:
|
||||
if response.status_code not in [200]:
|
||||
response_json = response.json()
|
||||
print("TCAOFF Branch-Add:", json.to_string(response_json))
|
||||
|
||||
# If the call succeeded:
|
||||
if response.status_code in [200]:
|
||||
@@ -312,9 +313,10 @@ def department_add(
|
||||
}
|
||||
)
|
||||
|
||||
# # Debugging:
|
||||
# response_json = response.json()
|
||||
# print("TCAOFF Dept-Add:", json.to_string(response_json))
|
||||
# Debugging:
|
||||
if response.status_code not in [200]:
|
||||
response_json = response.json()
|
||||
print("TCAOFF Dept-Add:", json.to_string(response_json))
|
||||
|
||||
# If the call succeeded:
|
||||
if response.status_code in [200]:
|
||||
@@ -417,8 +419,9 @@ def team_add(
|
||||
)
|
||||
|
||||
# Debugging:
|
||||
response_json = response.json()
|
||||
print("TCAOFF Team-Add:", json.to_string(response_json))
|
||||
if response.status_code not in [200]:
|
||||
response_json = response.json()
|
||||
print("TCAOFF Team-Add:", json.to_string(response_json))
|
||||
|
||||
# If the call succeeded:
|
||||
if response.status_code in [200]:
|
||||
@@ -431,6 +434,70 @@ def team_add(
|
||||
return False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def attendance_mark(
|
||||
tcaoff_creds: dict,
|
||||
user_id: int,
|
||||
status: Literal["P", "H", "A", "OT"],
|
||||
over_time: int | float,
|
||||
attendance_date: datetime.datetime | None = None,
|
||||
) -> bool:
|
||||
|
||||
"""
|
||||
Add a new department.
|
||||
:param tcaoff_creds: The set of credentials to use with the API call.
|
||||
:param user_id: The id of the user whose attendance is being marked.
|
||||
:param status: The status of the attendance.
|
||||
1. "P" for present,
|
||||
2. "H" for half-day,
|
||||
3. "A" for absent,
|
||||
4. "OT" for over-time.
|
||||
:param over_time: The amount of over-time work in hours.
|
||||
:param attendance_date: The date of the attendance. If not given, today's date will be used.
|
||||
:return: True if logged out, else False.
|
||||
"""
|
||||
|
||||
# Prepare the payload:
|
||||
json_payload = {
|
||||
"date": (
|
||||
date_time.parse_date_time(attendance_date) or
|
||||
date_time.get_current_date_time()
|
||||
).strftime("%Y-%m-%d"),
|
||||
"idUser": user_id,
|
||||
"status": status if over_time <= 0.0 else "OT",
|
||||
"ot": over_time,
|
||||
}
|
||||
|
||||
# Make the API call:
|
||||
response = requests.post(
|
||||
url = tcaoff_creds["urls"]["attendanceMark"],
|
||||
headers = {"X-Session-Token": tcaoff_creds["creds"]["sessionToken"]},
|
||||
json = json_payload
|
||||
)
|
||||
|
||||
# Debugging:
|
||||
if response.status_code not in [200]:
|
||||
try:
|
||||
response_json = response.json()
|
||||
print("TCAOFF Attendance-Mark:", json.to_string(response_json))
|
||||
except Exception as e:
|
||||
print("TCAOFF Attendance-Mark:", e)
|
||||
print("TCAOFF Attendance-Mark:", response.content)
|
||||
print("Payload:", json.to_string(json_payload))
|
||||
|
||||
# If the call succeeded:
|
||||
if response.status_code in [200]:
|
||||
print(f"TCAOFF: attendance for '{user_id}' marked")
|
||||
return True
|
||||
|
||||
# If the call failed:
|
||||
else:
|
||||
print(f"TCAOFF: attendance for '{user_id}' NOT marked")
|
||||
return False
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
|
||||
Reference in New Issue
Block a user