Пример #1
0
    async def set_notification(self, msg: BaseMessage, msg_text: t,
                               receivers: List[str], params: Schedule):

        recipients = []

        for r in receivers:
            try:
                recipients.append(msg.channel.address_book.find_contact(r))
            except ContactNotFoundException as e:
                raise CommandException(str(e))

        await msg.channel.schedule_send(
            msg_text=msg_text,
            recipients=recipients,
            params=params,
        )
        if params.is_repetitive:
            when_t = t(F'every {params.day_of_week.capitalize()}')
        else:
            when_t = t(params.date.strftime('%d.%m.%Y'))
        return t(*(
            t('When: ', when_t.b()).br(),
            t('Time: ',
              t(params.time.strftime('%H:%M')).b()).br(),
            t('Receivers: ',
              t(','.join(receivers)).b()).br(),
            t('Message: ', msg_text.b()),
        ))
Пример #2
0
def test_skype_formatting():
    formatter = SkypeFormatter()
    text_to_test = """When: <b raw_pre="*" raw_post="*">26.11.2019</b>
Time: <b raw_pre="*" raw_post="*">23:00</b>
Receivers: <b raw_pre="*" raw_post="*">Jane Doe</b>
Message: <b raw_pre="*" raw_post="*">check your inbox</b>"""
    text_structure = t(
        'When: ', t('26.11.2019').b().br(),
        'Time: ', t('23:00').b().br(),
        'Receivers: ', t('Jane Doe').b().br(),
        'Message: ', t('check your inbox').b(),
    )
    assert text_to_test == formatter.format(text_structure)
Пример #3
0
    async def show_notifications(self, command_input: str,
                                 message: BaseMessage):
        rows = []

        for j in scheduler.get_jobs():
            state = j.__getstate__()
            kwargs = state.get('kwargs')

            id = state['id']
            text = kwargs['text']
            recipients = ','.join(kwargs['recipients']) or '-'
            next_run_time = state.get('next_run_time')
            is_repetitive = 'No' if state.get(
                'trigger').__slots__ == 'run_date' else 'Yes'

            _date = next_run_time.strftime('%d.%m.%Y')
            _day_of_week = next_run_time.strftime('%A')
            _time = next_run_time.strftime('%H:%M')

            rows.append(
                t(*(
                    t(F'ID: {id}').br(),
                    t(F'Text: {text}').br(),
                    t(F'Recipients: {recipients}').br(),
                    t(F'Datetime/DOW: {_date} {_time} / {_day_of_week}').br(),
                    t(F'Is repetitive: {is_repetitive}').br(),
                )).br())

        return t(*rows) if len(rows) > 0 else 'There are no notify tasks'
Пример #4
0
    def get_creation_params(self, input_str: str) -> (t, Schedule):
        matches = self.create_pattern.match(input_str)
        if not matches:
            raise CommandException(EXCEPTION_MESSAGES['invalid_format'])
        parsed = matches.groupdict()
        day_of_week_adjective = parsed.get('day_of_week_adjective', None)

        if day_of_week_adjective:
            day_of_week_adjective = day_of_week_adjective.upper()
            _datetime = parse(parsed['day_of_week'])
            if not _datetime:
                CommandException(EXCEPTION_MESSAGES['not_recognized'].format(
                    entity='day of week',
                    value=parsed['day_of_week'],
                ))
            if day_of_week_adjective not in (self.NEXT, self.THIS, self.EVERY):
                raise CommandException('Unknown period specifier.')
            specifier = TimeSpecifier[day_of_week_adjective]
        else:
            specifier = None
            _datetime = parse(parsed['certain_date'])
            if not _datetime:
                raise CommandException(
                    EXCEPTION_MESSAGES['not_recognized'].format(
                        entity='date',
                        value=parsed['certain_date'],
                    ))

        _time = parse(parsed['certain_time'])
        if not _time:
            raise CommandException(
                EXCEPTION_MESSAGES['not_recognized'].format(
                    entity='time',
                    value=parsed['certain_time'],
                ), )
        _time = _time.time()
        _datetime = _datetime.replace(
            hour=_time.hour,
            minute=_time.minute,
        )
        return (
            t(parsed['msg']),
            parsed['receivers'].split(','),
            Schedule(
                datetime=_datetime,
                specifier=specifier,
            ),
        )
Пример #5
0
def test_formatting():
    formatter = HTMLFormatter()
    text_to_test = (
        "<b>Header</b>.<br>"
        "<b>Line: <i>1</i></b><br>"
        "Line: 2<br>"
        "Line: 3"
    )
    text_structure = t(
        t(t('Header').b(), '.').br(),
        t('Line: ', t('1').i()).b().br(),
        t('Line: 2').br(),
        'Line: 3',
    )
    assert text_to_test == formatter.format(text_structure)