From eac1820d3a7218f838025b17827f4e8f6aba90c6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 26 Dec 2019 14:58:55 +0100 Subject: [PATCH] Fix setedt verification --- TelegramEDT/EDTcalendar.py | 7 ++++--- TelegramEDT/edt.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/TelegramEDT/EDTcalendar.py b/TelegramEDT/EDTcalendar.py index 78ed2da..36bc40b 100644 --- a/TelegramEDT/EDTcalendar.py +++ b/TelegramEDT/EDTcalendar.py @@ -13,7 +13,8 @@ EMPTY_CALENDAR = "BEGIN:VCALENDAR\r\nPRODID:ics.py - http://git.io/lLljaA\r\nVER class Calendar(ics.Calendar): def __init__(self, time: str, resources: int, url: str = URL, projectid: int = 4, pass_week: bool = True): - super().__init__(self._get_calendar(url, resources, projectid)) + self.url = self._url(url, resources, projectid) + super().__init__(self._get_calendar(resources, projectid)) self.events = self._events(time, pass_week) self.timeline = Timeline(self) @@ -37,12 +38,12 @@ class Calendar(ics.Calendar): lastdate = now.date() + datetime.timedelta(days=7+(7-now.isoweekday())) return f"{url}?resources={resources}&projectId={projectid}&calType=ical&firstDate={firstdate}&lastDate={lastdate}" - def _get_calendar(self, url: str, resources: int, projectid: int): + def _get_calendar(self, resources: int, projectid: int): name = f"calendars/{resources}-{projectid}.ical" now = self._now().timestamp() if not isfile(name) or now-getmtime(name) < now-360: try: - calendar = requests.get(self._url(url, resources, projectid)).text + calendar = requests.get(self.url).text string_to_container(calendar) except (ParseError, requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout): if not isfile(name): diff --git a/TelegramEDT/edt.py b/TelegramEDT/edt.py index bb84ec1..151f184 100644 --- a/TelegramEDT/edt.py +++ b/TelegramEDT/edt.py @@ -7,7 +7,7 @@ from aiogram import types from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, InputTextMessageContent, \ InlineQueryResultArticle, InlineQuery, ContentType from aiogram.types import ParseMode -from ics.parse import ParseError +from ics.parse import ParseError, string_to_container from pyzbar.pyzbar import decode from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema @@ -108,7 +108,8 @@ async def await_cmd(message: types.message): resources = message.text try: - Calendar("", int(resources)) + string_to_container(requests.get(Calendar("", int(resources)).url).text) + except (ParseError, ConnectionError, InvalidSchema, MissingSchema, ValueError, UnboundLocalError): msg = lang(user, "setedt_err_res") else: