Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Update time formats
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Aug 5, 2023
1 parent 07813c7 commit dc5c0b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion schedule/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__name__ = "MySchedule.py"
__version__ = "1.0.5"
__version__ = "1.0.6"

from .api import ScheduleAPI
34 changes: 20 additions & 14 deletions schedule/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,19 @@ def get_timecard(self, week_end_date: str = None) -> List[Clock]:
:return: A timecard for the given week code
"""
data = {
"authToken": self.auth_token,
"reqType": "ESS",
"mm": "ESSTIMECARD",
"sm": "SUMMARY",
}
"authToken": self.auth_token,
"reqType": "ESS",
"mm": "ESSTIMECARD",
"sm": "SUMMARY",
}

if week_end_date is not None:
data.update({
"weekendDate": week_end_date,
"weekend": week_end_date,
})
data.update(
{
"weekendDate": week_end_date,
"weekend": week_end_date,
}
)

# Make a request to the timecard page
tc_request = self.session.post(
Expand Down Expand Up @@ -273,7 +275,7 @@ def get_timecard(self, week_end_date: str = None) -> List[Clock]:
if date_nodes and date_nodes[0] != " ":
date = date_nodes[0]
data_dict[date] = {"punches": []}

# Check if time and punch is present
if time_nodes and punch_type_nodes:
# Extract the time and punch type from the CDATA content
Expand Down Expand Up @@ -310,18 +312,22 @@ def get_timecard(self, week_end_date: str = None) -> List[Clock]:
clock_in_time = datetime.strptime(punch["time"], "%H:%M")

# Convert total seconds to hours and minutes
time_clocked_in_hours, remaining_seconds = divmod(time_clocked_in.seconds, 3600)
time_clocked_in_hours, remaining_seconds = divmod(
time_clocked_in.seconds, 3600
)
time_clocked_in_minutes = remaining_seconds // 60

time_clocked_out_hours, remaining_seconds = divmod(time_clocked_out.seconds, 3600)
time_clocked_out_hours, remaining_seconds = divmod(
time_clocked_out.seconds, 3600
)
time_clocked_out_minutes = remaining_seconds // 60

clocks.append(
Clock(
date,
punches,
f"{time_clocked_in_hours}:{time_clocked_in_minutes}",
f"{time_clocked_out_hours}:{time_clocked_out_minutes}"
f"{time_clocked_in_hours}:{time_clocked_in_minutes if time_clocked_in_minutes > 9 else f'0{time_clocked_in_minutes}'}",
f"{time_clocked_out_hours}:{time_clocked_out_minutes if time_clocked_out_minutes > 9 else f'0{time_clocked_out_minutes}'}",
)
)

Expand Down
24 changes: 16 additions & 8 deletions schedule/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ def __repr__(self) -> str:
+ ")"
)


class PunchType(Enum):
ShiftStart = "Shift Start"
BreakStart = "Meal Start"
BreakEnd = "Meal End"
ShiftEnd = "Shift End"


class Punch:
def __init__(self, punch_type: PunchType, time: str) -> None:
self.type = punch_type
Expand All @@ -61,18 +63,18 @@ def __repr__(self) -> str:
return f"Punch({self.type}, {self.time})"

def to_dict(self):
return {
"type": self.type.value,
"time": self.time
}
return {"type": self.type.value, "time": self.time}

@classmethod
def from_dict(cls, data):
punch_type = PunchType(data["type"])
return cls(punch_type, data["time"])


class Clock:
def __init__(self, date: str, punches: List[Punch], clocked_in_time: str, break_time: str) -> None:
def __init__(
self, date: str, punches: List[Punch], clocked_in_time: str, break_time: str
) -> None:
self.date = date
self.punches = punches
self.time_clocked_in = clocked_in_time
Expand All @@ -82,17 +84,23 @@ def __repr__(self) -> str:
data = "Clock("
for punch in self.punches:
data += punch.__repr__() + ", "
return data + f"Time Clocked in: {self.time_clocked_in}, Time Clocked out: {self.time_clocked_out}" + ")"
return (
data
+ f"Time Clocked in: {self.time_clocked_in}, Time Clocked out: {self.time_clocked_out}"
+ ")"
)

def to_dict(self):
return {
"date": self.date,
"punches": [punch.to_dict() for punch in self.punches],
"time_clocked_in": self.time_clocked_in,
"time_clocked_out": self.time_clocked_out
"time_clocked_out": self.time_clocked_out,
}

@classmethod
def from_dict(cls, data):
punches = [Punch.from_dict(punch_data) for punch_data in data["punches"]]
return cls(data["date"], punches, data["time_clocked_in"], data["time_clocked_out"])
return cls(
data["date"], punches, data["time_clocked_in"], data["time_clocked_out"]
)

0 comments on commit dc5c0b2

Please # to comment.