Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Google Calendar duplicates #8

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
iburakov marked this conversation as resolved.
Show resolved Hide resolved
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
Loading