コード例 #1
0
ファイル: trails.py プロジェクト: pykarimov/spbu4u
def to_home_or_univer_handler(call_back):
    user = g.current_tbot_user

    if call_back.data == "В Универ":
        from_code = user.home_station_code
        to_code = user.univer_station_code
    else:
        from_code = user.univer_station_code
        to_code = user.home_station_code

    answer = fast_trail_answer_select_day.format(
        from_title=nf.get_key_by_value(all_stations, from_code),
        to_title=nf.get_key_by_value(all_stations, to_code))
    bot.edit_message_text(text=answer,
                          chat_id=user.tg_id,
                          message_id=call_back.message.message_id,
                          reply_markup=select_day_keyboard(),
                          parse_mode="HTML")
コード例 #2
0
ファイル: week.py プロジェクト: pykarimov/spbu4u
def select_week_day_schedule_handler(call_back):
    user = g.current_tbot_user

    if call_back.data == "Вся неделя":
        day = "Неделя"
    else:
        day = nf.get_key_by_value(week_day_titles, call_back.data)

    bot.edit_message_text(text="Расписание на: <i>{0}</i>\n".format(day),
                          chat_id=user.tg_id,
                          message_id=call_back.message.message_id,
                          parse_mode="HTML",
                          reply_markup=current_next_keyboard())
コード例 #3
0
 def de_json(self, event):
     self.name = event["Subject"].split(", ")[0]
     self.types = [event["Subject"].split(", ")[1]]
     self.days = [
         nf.get_key_by_value(dct=week_day_number,
                             val=nf.datetime_from_string(
                                 event["Start"]).date().isoweekday())
     ]
     self.times = [nf.parse_event_time(event).split()[1]]
     self.educators = [
         e["Item2"].split(", ")[0] for e in event["EducatorIds"]
     ]
     self.locations = [p["DisplayName"] for p in event["EventLocations"]]
     return self
コード例 #4
0
    def test_text_to_date_dm(self, text_t=None, y=None, s=None):
        if not text_t:
            text_t = "{0}{3}{1:0>2}"
        if not y:
            y = None
        if not s:
            ss = [" ", "."]
        else:
            ss = [s]

        for c in ss:
            for m in range(1, 13):
                self.test_text_to_date_d(text_t, m, y, c)
                self.test_text_to_date_d(text_t,
                                         nf.get_key_by_value(const.months, m),
                                         y, c)
コード例 #5
0
    def get_block_answer(self, for_date, block_num=1):
        """
        Creates block answer number `block_num` for input date

        :param for_date: date for schedule
        :type for_date: date
        :param block_num: (Optional) wanted block's human number (NOT AN INDEX)
        :type block_num: int
        :return:
        :rtype: str
        """
        events = self._get_events(from_date=for_date,
                                  to_date=for_date + timedelta(days=1))
        if not events:
            return no_lessons_answer
        else:
            events = events[0]

        blocks = nf.create_events_blocks(events["DayStudyEvents"])
        block = blocks[block_num - 1]

        answer = "<b>" + str(block_num) + " из " + str(
            len(blocks)) + "</b>\n\n"

        answer += nf.parse_event_time(
            block[0]) + " <i>(" + nf.get_key_by_value(
                week_day_number, for_date.isoweekday()) + ")</i>" + "\n\n"

        for num, event in enumerate(block, start=1):
            lesson = Lesson().de_json(event)

            hide_mark = ""
            for skip in self.hidden_lessons.filter_by(name=lesson.name):
                if lesson.is_skipped_by(skip):
                    hide_mark = emoji["cross_mark"] + " "
                    break

            answer += str(num) + ". " + hide_mark + nf.parse_event_sub_loc_edu(
                event=event, full_place=self.is_full_place)
        return answer + hide_lesson_answer