Skip to content

Commit

Permalink
Merge pull request #182 from ebbeflarup/localize/huskelisten_dueDate
Browse files Browse the repository at this point in the history
Localized dueDate på Huskelisten
  • Loading branch information
scaarup authored Oct 12, 2024
2 parents 5a955cf + 2454257 commit 5ae796e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
}
}
},
"remoteUser": "root"
"remoteUser": "root",
"remoteEnv": {
"TZ": "Europe/Copenhagen"
}
}
44 changes: 30 additions & 14 deletions custom_components/aula/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,16 @@ def ugeplan(week, thisnext):
# _LOGGER.debug("ugeplaner response "+str(ugeplaner.text))
try:
for person in ugeplaner.json()["personer"]:
ugeplan = person["institutioner"][0]["ugebreve"][0]["indhold"]
ugeplan = person["institutioner"][0]["ugebreve"][0][
"indhold"
]
if thisnext == "this":
self.ugep_attr[person["navn"].split()[0]] = ugeplan
elif thisnext == "next":
self.ugepnext_attr[person["navn"].split()[0]] = ugeplan
except:
_LOGGER.debug("Cannot fetch ugeplaner, so setting as empty")
_LOGGER.debug("ugeplaner response "+str(ugeplaner.text))
_LOGGER.debug("ugeplaner response " + str(ugeplaner.text))

if "0030" in self.widgets:
_LOGGER.debug("In the MU Opgaver flow")
Expand Down Expand Up @@ -617,7 +619,7 @@ def is_correct_format(date_string, format):

children = "&children=".join(self._childuserids)
institutions = "&institutions=".join(self._institutionProfiles)
timedelta = datetime.datetime.now() + datetime.timedelta(days=180)
timedelta = datetime.datetime.now() + datetime.timedelta(days=7)
From = datetime.datetime.now().strftime("%Y-%m-%d")
dueNoLaterThan = timedelta.strftime("%Y-%m-%d")
get_payload = (
Expand Down Expand Up @@ -663,17 +665,26 @@ def is_correct_format(date_string, format):
reminders = person["teamReminders"]
if len(reminders) > 0:
for reminder in reminders:
mytime = datetime.datetime.strptime(
local_timezone = (
datetime.datetime.now(datetime.timezone.utc)
.astimezone()
.tzinfo
)
due_date = datetime.datetime.strptime(
reminder["dueDate"], "%Y-%m-%dT%H:%M:%SZ"
)
ftime = mytime.strftime("%A %d. %B")
huskel = huskel + "<h3>" + ftime + "</h3>"
huskel = (
huskel
+ "<b>"
+ reminder["subjectName"]
+ "</b><br>"
local_due_date = (
due_date.replace(tzinfo=datetime.timezone.utc)
.astimezone(local_timezone)
.strftime("%A %d. %B")
)
huskel = huskel + "<h3>" + local_due_date + "</h3>"
subjectName = (
reminder["subjectName"]
if "subjectName" in reminder
else ""
)
huskel = huskel + "<b>" + subjectName + "</b><br>"
huskel = (
huskel + "af " + reminder["createdBy"] + "<br><br>"
)
Expand Down Expand Up @@ -727,8 +738,11 @@ def is_correct_format(date_string, format):
data = json.loads(response.text, strict=False)
# _LOGGER.debug("Meebook ugeplan raw response from week "+week+": "+str(response.text))

if 'exceptionMessage' in data:
_LOGGER.warning("Ignoring error in fetching data from Meebook. Error exception message: " + data['exceptionMessage'])
if "exceptionMessage" in data:
_LOGGER.warning(
"Ignoring error in fetching data from Meebook. Error exception message: "
+ data["exceptionMessage"]
)
else:
for person in data:
_LOGGER.debug("Meebook ugeplan for " + person["name"])
Expand All @@ -739,7 +753,9 @@ def is_correct_format(date_string, format):
if len(day["tasks"]) > 0:
for task in day["tasks"]:
if not task["pill"] == "Ingen fag tilknyttet":
ugep = ugep + "<b>" + task["pill"] + "</b><br>"
ugep = (
ugep + "<b>" + task["pill"] + "</b><br>"
)
ugep = ugep + task["author"] + "<br><br>"
content = re.sub(
r"([0-9]+)(\.)", r"\1\.", task["content"]
Expand Down

0 comments on commit 5ae796e

Please sign in to comment.