Ejemplo n.º 1
0
    def get_navigation_bar(self, target_date=None):
        if target_date is None:
            target_date = self.get_now()
            today_right = True
        else:
            today_right = target_date.date() == self.get_now().date()

        previous_date = target_date - timedelta(days=1)
        previous_date_button = ('< {}'.format(
            strings.format_date(previous_date)),
                                strings.go_date_fun(previous_date))
        next_date = target_date + timedelta(days=1)
        next_date_button = ('{} >'.format(strings.format_date(next_date)),
                            strings.go_date_fun(next_date))

        if today_right:
            return strings.get_inline_keyboard([[
                previous_date_button,
                (strings.refresh_string,
                 json.dumps({'type': 'refresh'}, separators=(',', ':'))),
                next_date_button
            ]])
        else:
            return strings.get_inline_keyboard([[
                previous_date_button,
                (strings.today_string,
                 json.dumps({
                     'type': 'GoDate',
                     'to': strings.today_string_label,
                 })), next_date_button
            ]])
Ejemplo n.º 2
0
 def get_go_to_pairs_choose():
     return InlineKeyboardMarkup(
         strings.get_inline_keyboard(
             [[
                 (
                     strings.go_to_pairs_choose_keyboard_message,
                     json.dumps({'type': 'go_to_pairs'})
                 )
             ]]
         )
     )
Ejemplo n.º 3
0
 def find_free_auditoriums_keyboard(building_id: int,
                                    date: datetime = None):
     if date is None:
         date = MainState.get_now()
     return strings.get_inline_keyboard([[
         (strings.free_auditoriums_keyboard_message,
          json.dumps({
              'type': 'free',
              'date': strings.format_date(date),
              'building': building_id,
          }))
     ]])
Ejemplo n.º 4
0
 def go_date(self, date, invoke=False):
     if date.date() == self.get_now().date():
         self.send_menu_message(invoke=invoke)
         return
     try:
         timetable = self.get_timetable_date(date)
     except python_ruz.utilities.WrongTimePeriod:
         self.user.send_or_edit_message(
             strings.too_far_error.format(strings.format_date(date)),
             invoke=invoke,
             reply_markup=InlineKeyboardMarkup(
                 strings.get_inline_keyboard([[
                     (strings.today_string,
                      json.dumps(
                          {
                              'type': 'GoDate',
                              'to': strings.today_string_label
                          },
                          separators=(',', ':')))
                 ]])))
         return
     if len(timetable) == 0:
         self.user.send_or_edit_message(strings.no_lessons_at_date.format(
             strings.format_date(date), strings.get_weekday_name(date)),
                                        invoke=invoke,
                                        parse_mode=ParseMode.MARKDOWN,
                                        reply_markup=InlineKeyboardMarkup(
                                            self.get_navigation_bar(date)))
     else:
         building_id = self.get_building_from_timetable(timetable)
         self.user.send_or_edit_message(
             self.format_timetable(timetable),
             invoke=invoke,
             parse_mode=ParseMode.MARKDOWN,
             reply_markup=InlineKeyboardMarkup(
                 self.get_navigation_bar(date) +
                 self.find_free_auditoriums_keyboard(building_id, date)))
Ejemplo n.º 5
0
 def get_refresh_bar():
     return strings.get_inline_keyboard([[(strings.refresh_string,
                                           json.dumps({'type': 'refresh'},
                                                      separators=(',',
                                                                  ':')))]])