diff --git a/.gitignore b/.gitignore index 4370e35..59d6915 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__ *.sqlite3 *.save +*.xls /audio /tts-gc-key.json /test.py diff --git a/Zieit/Zieit.py b/Zieit/Zieit.py index 51bff74..9ac84c8 100644 --- a/Zieit/Zieit.py +++ b/Zieit/Zieit.py @@ -1,4 +1,9 @@ from Command import Command # import parent class +import urllib.request +import xlrd +import xlwt +from xlutils.copy import copy +from datetime import datetime class Zieit (Command): lessonsStartTime = ['07:55','09:25','11:05','12:35','14:05','15:45','17:15'] @@ -7,8 +12,8 @@ class Zieit (Command): def start(this, string): # main method pass - @staticmethod - def getShedule(): + @classmethod + def getShedule(self): url = 'https://www.zieit.edu.ua/wp-content/uploads/Rozklad/2k.xls' name = url.split('/')[-1] urllib.request.urlretrieve(url, name) @@ -52,18 +57,19 @@ class Zieit (Command): lesson['type'] = row[14] return week - @staticmethod - def getTodaysShedule(): - week = getShedule() + @classmethod + def getTodaysShedule(self): + week = self.getShedule() for d, lessons in week.items(): date = datetime.strptime(d, "%d.%m.%Y").date() today = datetime.now().date() if date == today: return lessons return None - @staticmethod - def getNextLesson(lessonsTime): - lessons = getTodaysShedule() + @classmethod + def getNextLesson(self, lessonsTime): + lessons = self.getTodaysShedule() + if lessons == None: return None next = {} for i, lesson in lessons.items(): border = datetime.strptime(lessonsTime[i-1], '%H:%M').time() diff --git a/Zieit/myshedule.py b/Zieit/myshedule.py index 1f713d4..2041c4e 100644 --- a/Zieit/myshedule.py +++ b/Zieit/myshedule.py @@ -1,10 +1,6 @@ from .Zieit import * -import urllib.request -import xlrd -import xlwt -from xlutils.copy import copy ################################################################################ -def nextLesson(params): +def nextLessonMethod(params): lesson = Zieit.getNextLesson(Zieit.lessonsStartTime) if lesson == None: voice = text = 'Сегодня пар нет' else: @@ -23,4 +19,4 @@ def nextLesson(params): keywords = {} patterns = ['* следующ* (предмет|урок|пара)'] nextLesson = Zieit('Next Lesson', keywords, patterns) -nextLesson.setStart(nextLesson) +nextLesson.setStart(nextLessonMethod) diff --git a/telegram_bot.py b/telegram_bot.py index f212176..093e4b4 100644 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -5,6 +5,7 @@ import Text2Speech import telebot import config import modules +import time threads = [] online = True @@ -70,4 +71,5 @@ while True: print("Start polling...") bot.polling(callback = check_threads, args = (threads,) ) except: + time.sleep(10) print("Polling failed")