Skip to content

Commit

Permalink
Merge pull request #8 from Myp3a/main
Browse files Browse the repository at this point in the history
fix: Google Calendar duplicates
  • Loading branch information
iburakov authored Sep 16, 2024
2 parents 5e8b715 + 730d6a5 commit 361385a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "my-itmo-ru-to-ical"
version = "1.0.0"
version = "1.1.0"
description = "A simple app exporting the scheudle from my.itmo.ru in iCalendar format."
authors = ["iburakov <speedwatson@gmail.com>"]
license = "MIT"
Expand Down
15 changes: 15 additions & 0 deletions src/lessons_to_events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import datetime, timedelta
from hashlib import md5
from uuid import UUID

from dateutil.parser import isoparse
from ics import Event
Expand Down Expand Up @@ -50,6 +52,18 @@ def _raw_lesson_to_location(raw_lesson: dict):
return result if result else None


def _raw_lesson_to_uuid(raw_lesson: dict):
elements = [
raw_lesson["date"],
raw_lesson["time_start"],
raw_lesson["subject"],
]
result = ", ".join(elements)
md5_of_lesson = md5(result.encode("utf-8")).hexdigest()
result_uuid = str(UUID(hex=md5_of_lesson))
return result_uuid


def raw_lesson_to_event(raw_lesson: dict) -> Event:
begin = isoparse(f"{raw_lesson['date']}T{raw_lesson['time_start']}:00+03:00")
end = isoparse(f"{raw_lesson['date']}T{raw_lesson['time_end']}:00+03:00")
Expand All @@ -62,6 +76,7 @@ def raw_lesson_to_event(raw_lesson: dict) -> Event:
end=end,
description=_raw_lesson_to_description(raw_lesson),
location=_raw_lesson_to_location(raw_lesson),
uid=_raw_lesson_to_uuid(raw_lesson),
)
if raw_lesson["zoom_url"]:
event.url = raw_lesson["zoom_url"]
Expand Down

0 comments on commit 361385a

Please sign in to comment.