Exemple #1
0
 def show_auditoriums(self, pair_no):
     if self.free_auditoriums is None:
         self.got_auditoriums_callback = functools.partial(self.show_auditoriums, pair_no)
         self.user.send_or_edit_message(
             strings.getting_free_auditoriums,
             invoke=False,
             reply_markup=self.get_go_to_pairs_choose()
         )
     else:
         try:
             pairs_list = [auditorium_name
                           for auditorium_name, pairs_availability
                           in self.free_auditoriums.items()
                           if pairs_availability[pair_no - 1]]
             pairs_list.sort()
             pairs_list_str = ', '.join(map(str, pairs_list))
             self.user.send_or_edit_message(
                 strings.free_auditoriums_list_format.format(strings.format_date(self.date),
                                                             strings.get_weekday_name(self.date),
                                                             self.building.building_address,
                                                             pair_no,
                                                             pairs_list_str),
                 invoke=False,
                 reply_markup=self.get_go_to_pairs_choose(),
                 parse_mode=ParseMode.MARKDOWN,
             )
         except:
             self.user.send_or_edit_message(strings.error_during_getting_schedule,
                                            invoke=True)
             logger.error('Error while getting free auditoriums {} {} {}'.format(
                 self.date,
                 self.building.building_oid,
                 repr(self.free_auditoriums)),
             )
             return BasicState.create_transition(tags.MAIN, invoke=True)
Exemple #2
0
 def main_message(self, invoke=False):
     self.user.send_or_edit_message(
         strings.free_auditoriums_main_message.format(
             strings.format_date(self.date),
             strings.get_weekday_name(self.date),
             self.building.building_address),
         invoke=invoke,
         parse_mode=ParseMode.MARKDOWN,
         reply_markup=InlineKeyboardMarkup(self.get_pairs_keyboard()))
Exemple #3
0
 def format_timetable(timetable: List[Lesson]):
     first_lesson_date = timetable[0].begin_lesson.date()
     first_lesson_building = timetable[0].building.building_address
     if first_lesson_date != MainState.get_now().date():
         start = '*{} ({})*\n_{}_\n'.format(
             strings.format_date(first_lesson_date),
             strings.get_weekday_name(first_lesson_date),
             first_lesson_building)
     else:
         start = '*{}*'.format(strings.today_string)
     if len(start) > 0:
         start += '\n'
     return start + strings.division_line.join(
         i.format_lesson(strings.timetable_base, strings.date_format,
                         strings.time_format) for i in timetable).strip()
Exemple #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)))