|
|
|
@ -0,0 +1,54 @@ |
|
|
|
from dateutil.parser import parse as datetime_parse |
|
|
|
import pytz |
|
|
|
import datetime |
|
|
|
from gapi.apis.calendar_api.models import Event |
|
|
|
|
|
|
|
|
|
|
|
class Shift: |
|
|
|
def __init__( |
|
|
|
self, |
|
|
|
start: datetime.datetime, |
|
|
|
end: datetime.datetime, |
|
|
|
role, |
|
|
|
location, |
|
|
|
other=None, |
|
|
|
): |
|
|
|
self.start = start |
|
|
|
self.end = end |
|
|
|
self.role = role |
|
|
|
self.other = other |
|
|
|
self.location = location |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_dict(cls, _dict, cafe_info, timezone_string): |
|
|
|
location = f"""{cafe_info["address"]["street"]}, {cafe_info["address"]["city"]}, {cafe_info["address"]["state"]} {cafe_info["address"]["zipcode"]}""" |
|
|
|
role = _dict["workstationName"] |
|
|
|
start_naive = datetime_parse(_dict["startDateTime"]) |
|
|
|
end_naive = datetime_parse(_dict["endDateTime"]) |
|
|
|
timezone = pytz.timezone(timezone_string) |
|
|
|
start = timezone.localize(start_naive) |
|
|
|
end = timezone.localize(end_naive) |
|
|
|
return cls(start, end, role, location) |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_Event(cls, event: Event): |
|
|
|
other = [] |
|
|
|
for line in event.description.split("\n"): |
|
|
|
if "Role" in line: |
|
|
|
key, role = line.split(": ", 1) |
|
|
|
else: |
|
|
|
other.append(line) |
|
|
|
return cls( |
|
|
|
event.start, |
|
|
|
event.end, |
|
|
|
role, |
|
|
|
event.location, |
|
|
|
"\n".join(other) if len(other) > 0 else None, |
|
|
|
) |
|
|
|
|
|
|
|
def to_Event(self): |
|
|
|
description = f"""Role: {self.role} |
|
|
|
{self.other if self.other is not None else ""}""" |
|
|
|
return Event( |
|
|
|
self.start, self.end, "Panera shift", description, location=self.location |
|
|
|
) |