def parse_args(self, message, attachment): self.message = "" if message: try: m = message.split("\n") self.id = int(m[0].strip()) if self.id < 2: raise exceptions.NikolayException("Введите id > 2") self.message = "\n".join(m[1:]) if not self.message and not attachment: raise exceptions.NikolayException("Пожалуйста, заполните сообщение") except ValueError: raise exceptions.NumFormatError("Не могу распознать id. ") else: raise exceptions.NotEnoughArgs(2, 0)
def __get_schedule_cell(self, date, num): i = 2 while self.schedule.cell(row=i, column=1).value: if self.schedule.cell(row=i, column=1).value.date() == date: return self.schedule.cell(row=i, column=num + 1) i = i + 1 raise exceptions.NikolayException( "Не удалось найти указанную дату в расписании.")
def exec(self, message, attachment): self.parse_args(message) eio = excel.ExcelIO() info = eio.info_read(self.id) if not info[1]: raise exceptions.NikolayException('Не удалось найти сообщение с id=%d' % self.id) eio.info_write(info[1], self.date, info[3], info[4], info[0]) eio.save() return [("Сообщение успешно перенесено", "")]
def parse_args(self, message): super().parse_args(message) self.check_args() try: self.id = int(self.args[0]) if self.id < 2: raise exceptions.NikolayException("Введите id > 2") except ValueError: raise exceptions.NumFormatError("Не могу распознать id. ")
def parse_args(self, message): self.message = "" if message: m = message.split("\n") self.date = utility.parse_date(m[0].strip()) self.message = "\n".join(m[1:]) else: raise exceptions.NotEnoughArgs(2, 0) if not self.message: raise exceptions.NikolayException("Пожалуйста, введите текст сообщения")
def parse_args(self, message): if message.startswith("-архив"): self.archive = True self.q = message.replace("-архив", "").strip() if not self.q: raise exceptions.NikolayException('Пожалуйста, введите запрос') self.date = datetime.fromtimestamp(0).date() else: self.archive = False self.q = message self.date = datetime.now(timezone(timedelta(hours=3))).date()
def exec(self, message, attachment): self.parse_args(message) eio = excel.ExcelIO() cell_value = self._clear_cell(eio, self.date, self.num) lst = cell_value.split(", ") if len(lst) < 2: raise exceptions.NikolayException("Что-то не так с ячейкой в файле расписания") lst[-1] = self.classroom cell_value = ", ".join(lst) self._write_cell(eio, self.date, self.num, cell_value) eio.save() return [("Пара успешно обновлена", "")]
def exec(self, message, attachment): self.parse_args(message, attachment) eio = excel.ExcelIO() dt = datetime.now(timezone(timedelta(hours=3))) info = eio.info_read(self.id) if not info[1]: raise exceptions.NikolayException('Не удалось найти сообщение с id=%d' % self.id) if self.message: info[3] = self.message if attachment: info[4] = attachment eio.info_write(info[1], info[2], info[3], info[4], info[0]) eio.save() return [("Сообщение успешно обновлено", "")]
def exec(self, message, attachment): self.parse_args(message) response = "" if len(self.args) == 1: try: result = self.commands[self.args[0]] response = response + result.__doc__ + '\n' except KeyError: raise exceptions.NikolayException("Я не смог найти команду %s. \n\ Воспользуйтесь !помощь для получения списка команд" % self.args[0]) else: response = "Список команд:\n" for k in self.commands.keys(): response = response + k + '\n' return [(response, "")]
def get_info(self, q, date): i = 2 count = 0 messages = [] while self.info.cell(row=i, column=1).value: added = self.info.cell(row=i, column=1).value deadline = self.info.cell(row=i, column=2).value text = self.info.cell(row=i, column=3).value attachment = self.info.cell(row=i, column=4).value if deadline.date() >= date and q in text: count = count + 1 message = "%d. дата добавления: %s\nдата окончания: %s\n" \ % (i, added.date(), deadline.date()) + text messages.append((message, attachment)) i = i + 1 if not count: raise exceptions.NikolayException('Информация отсутствует') return messages
def get_schedule(self, date, delta=1): response = "" i = 2 while self.schedule.cell(row=i, column=1).value: if self.schedule.cell(row=i, column=1).value.date() == date: for k in range(i, i + delta): day = date + timedelta(k - i) response = response + utility.weekdays[ day.weekday()] + " " + str(day) + "\n" daily = "" for j in range(2, 9): cl = self.schedule.cell(row=k, column=j) if cl.value: daily = daily + str(j - 1) + ") " + cl.value + '\n' if daily == "": daily = "Выходной, отдыхаем\n\n" response = response + daily + '\n' return response i = i + 1 raise exceptions.NikolayException( "Не удалось найти указанную дату в расписании.")
def info_delete(self, id): if self.info[id][0].value: self.info.delete_rows(id) else: raise exceptions.NikolayException( 'Не удалось найти сообщение с id=%d' % id)