1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramEDT/EDTcalendar.py

39 lines
1.3 KiB
Python
Raw Normal View History

2019-09-16 22:02:24 +02:00
import datetime
import ics
import requests
from ics.timeline import Timeline
from aiogram.utils import markdown
class Calendar(ics.Calendar):
def __init__(self, url: list, firstdate: datetime.date, lastdate: datetime.date):
super().__init__(requests.get(
f"{url[0]}?resources={url[1]}&projectId={url[2]}&calType=ical&firstDate={firstdate}&lastDate={lastdate}"
).text)
events = set()
for e in self.events:
events.add(Event(e))
self.events = events
self.timeline = Timeline(self)
class Event(ics.Event):
def __init__(self, event: ics.Event):
super().__init__()
for v in event.__dict__:
setattr(self, v, event.__dict__[v])
self.begin = self.begin.datetime.replace(tzinfo=datetime.timezone.utc).astimezone(tz=None)
self.end = self.end.datetime.replace(tzinfo=datetime.timezone.utc).astimezone(tz=None)
self.organizer = self.description.split('\n')[3]
def __str__(self):
return markdown.text(
markdown.bold(f"<{str(self.begin.date())[5:]}>"),
markdown.code(f"📓[{self.name}]:"),
markdown.text(f"⌚️ {str(self.begin.time())[:-3]} -> {str(self.end.time())[:-3]}"),
markdown.italic(f"📍 {self.location} 👨‍🏫 {self.organizer}"),
sep="\n"
)