コード例 #1
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def give_subject_hw(message):
    text = message.text
    mode = get_mode()
    try:
        text = int(text)
    except ValueError:
        choose_dates(message)  #calender work
        return 0
    else:
        try:
            mode = int(mode)
        except ValueError:
            sub = text - int(mode[-1])
        else:
            sub = text - mode
        if sub > 0:
            send(message, 'Нет дз на следующие четверти')
            start(message)
            return 0
        dates = date_range(quarters_dates[text]['begin'],
                           quarters_dates[text]['end'])
        for d in dates:
            get_hw(message,
                   d,
                   sub=ru_to_en(chosen_subjects[message.chat.id]),
                   hwNotFoundMessage=False)
    start(message)
コード例 #2
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def push_konspekt_subject_choose(message):
    chosen_subjects[message.chat.id] = ru_to_en(message.text)
    sent = send(message,
                'Отошлите файл pdf с конспектом по предмету "%s"' %
                (message.text),
                return_fun=True)
    bot.register_next_step_handler(sent, push_konspekt)
コード例 #3
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def rm_hw(message):
    path = path_to_hwbot_v2 + '/data/hw/%s/%s.txt' % (ru_to_en(
        message.text), chosen_dates[message.chat.id])
    try:
        os.remove(path)
    except FileNotFoundError:
        send(message, 'Не найдено файла ' + path)
    else:
        send(message, 'Файл ' + path + ' удалён.')
    finally:
        start(message)
コード例 #4
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def send_konspekt(message):
    subject = ru_to_en(message.text)
    try:
        konspekt = open(
            path_to_hwbot_v2 + '/data/konspektus/%s.pdf' % (subject), 'rb')
    except FileNotFoundError:
        send(message, 'Не найдено конспекта по предмету "%s"' % (message.text))
    else:
        bot.send_document(message.chat.id, konspekt)
        konspekt.close()
    finally:
        start(message)
コード例 #5
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def get_days(call):
    # send(call.message, '%i\n%i'%(active_calendars[call.message.chat.id], call.message.date))
    if active_calendars.get(call.message.chat.id, 0) != call.message.date:
        bot.answer_callback_query(call.id, text="")
        return
    chat_id = call.message.chat.id
    saved_date = current_shown_dates.get(chat_id)
    if (saved_date is not None):
        day = call.data[12:]
        d = str(
            datetime.datetime(int(saved_date[0]), int(saved_date[1]), int(day),
                              0, 0, 0))
        d = '%s.%s.%s' % (d[8:10], d[5:7], d[:4])
        send(call.message, d)
        if chosen_dates.get(chat_id, []) == []:
            chosen_dates[chat_id] = [d]
        else:
            chosen_dates[chat_id].append(d)
            begin = get_date(chosen_dates[chat_id][0])
            end = get_date(d)
            if (begin - end).days > 0:
                begin, end = end, begin
            subject = chosen_subjects[chat_id]
            dates = date_range(*[
                '{:02d}.{:02d}.{:04d}'.format(d.day, d.month, d.year)
                for d in [begin, end]
            ])
            nohw = True
            for dates_elem in dates:
                # get_hw(call.message, dates_elem, sub = ru_to_en(chosen_subjects[chat_id]), hwNotFoundMessage = False)
                if get_hw(call.message,
                          dates_elem,
                          sub=ru_to_en(chosen_subjects[chat_id]),
                          hwNotFoundMessage=False) != 0:
                    nohw = False
            if nohw == True:
                send(call.message, 'Не найдено дз на этот диапозон дат.')
            del (chosen_dates[chat_id])
        bot.answer_callback_query(call.id, text="")

    else:
        #Do something to inform of the error
        pass
コード例 #6
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def add_hw_step2(message):
    found = False
    for day in range(1, 8):
        if ((datetime.datetime.today() +
             datetime.timedelta(days=day)).weekday() != 6) and (
                 chosen_subjects.get(message.chat.id)
                 in table.get_all()[(datetime.datetime.today() +
                                     datetime.timedelta(days=day)).weekday()]):
            found = True
            break
    if not (found):
        send(message, 'не найдено дня с этим предметом')
        start(message)
        return 0
    day = str_date(datetime.datetime.today() + datetime.timedelta(days=day))
    print(day)
    hwf = open(
        path_to_hwbot_v2 + '/data/hw/%s/%s.txt' %
        (ru_to_en(chosen_subjects.get(message.chat.id)), day), 'w')
    hwf.write(message.text)
    hwf.close()
    start(message)
コード例 #7
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def sub_to_change(message):
    chosen_subjects[message.chat.id] = ru_to_en(message.text)
    sent = send(message, 'Введите дату в формате dd.mm.yyyy:', return_fun=True)
    bot.register_next_step_handler(sent, date_to_change)
コード例 #8
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def push_file_subject_choose(message):
    chosen_subjects[message.chat.id] = ru_to_en(message.text)
    sent = send(message, 'Наберите имя файла:', return_fun=True)
    bot.register_next_step_handler(sent, push_file_choose_name)
コード例 #9
0
ファイル: main.py プロジェクト: Cow-berry/hwbot_v2
def get_hw(message, day, sub=False, hwNotFoundMessage=True):
    #mode = get_mode()
    #try:
    #    mode = int(mode)
    #except ValueError:
    #    try:
    #        holyday = open(path_to_hwbot_v2 + '/data/holydays/' + mode[-1] + '.txt', 'r')
    #    except FileNotFoundError:
    #        send(message, 'Нет файла ' + '/data/holydays/' + mode[-1] + '.txt')
    #    else:
    #        hw = holydays.readlines()
    #        holyday.close()
    #        send(message, 'Есть файла ' + '/data/holydays/' + mode[-1] + '.txt')
    #        send(message, ''.join(holyday))
    #    finally:
    #        return 0
    d = day.split('.')
    day = '%s.%s.%s' % (d[2], d[1], d[0])
    name = day + '.txt'
    hw = {}
    if not sub:
        list_of_subjects = subjects
    else:
        list_of_subjects = [sub]
    for subject in list_of_subjects:
        try:
            f = open(
                path_to_hwbot_v2 + '/data/hw/%s/%s' %
                (ru_to_en(subject), name), 'r')
        except FileNotFoundError:
            pass
        else:
            # hw[subject] = ''.join(f.readlines())
            hw[subject] = f.readlines()
            f.close()
    if hw == {}:
        if not (hwNotFoundMessage):
            return 0
        send(message, 'Домашнее задание на %s отсутствует' % (day))
        return
    res = day + ':\n'
    files = []
    hw_iter = copy.deepcopy(hw)
    for subject in hw_iter:
        for i in range(len(hw_iter[subject])):
            if hw_iter[subject][i].startswith('file '):
                files.append(
                    '/data/hw/%s/%s' %
                    (ru_to_en(subject), hw_iter[subject][i].split()[1]))
                hw[subject].remove(hw_iter[subject][i])
    for sub in hw:
        homework = hw[sub]
        res += '<b>%s</b>:\n%s\n' % (en_to_ru(sub), ''.join(homework))
    # if (res == day + ':\n') and mul:
    #     return
    send(message, res)
    # send(message, '\n'.join(files))
    for file_path in files:
        try:
            file = open(path_to_hwbot_v2 + file_path, 'rb')
        except FileNotFoundError:
            bot.send_message(
                config.admin_id_list[0],
                'Не могу открыть файл %s' % (path_to_hwbot_v2 + file_path))
        else:
            if file_path[-3:] in ['jpg', 'png']:
                bot.send_photo(message.chat.id, file)
            else:
                bot.send_document(message.chat.id, file)
            file.close()