Пример #1
0
    def _print_posts(self):
        try:
            posts = self._server.get_all_posts(self._user_id)
        except Fault as ex:
            print(get_message(ex))

            return

        print(format_posts(posts))
Пример #2
0
    def _add_post(self):
        subject = ask_user('Subject:')
        title = ask_user('Title:')
        body = ask_user('Body:')

        try:
            self._server.add_post(self._user_id, subject, title, body)
        except Fault as ex:
            print(get_message(ex))
Пример #3
0
    def _subscribe(self):
        subject = ask_user('Subject:')

        try:
            posts = self._server.subscribe(self._user_id, subject)
        except Fault as ex:
            print(get_message(ex))

            return

        print()
Пример #4
0
    def _create_user(self):
        user_id = ask_user('User identification:')

        try:
            self._server.register_user(user_id)
        except Fault as ex:
            print(get_message(ex))

            return

        self._user_id = user_id
Пример #5
0
    def _add_subject(self):
        subject_name = ask_user('Subject name:')

        try:
            posts_limit = int(ask_user('Posts limit:'))
        except ValueError:
            print('Not a valid number')

            return

        try:
            self._server.add_subject(self._user_id, subject_name, posts_limit)
        except Fault as ex:
            print(get_message(ex))
Пример #6
0
    def _print_filtered_posts(self):
        subject = ask_user('Subject:')
        min_date = ask_user('Minimum date (yyyy-MM-dd hh:mm):')
        max_date = ask_user('Maximum date (yyyy-MM-dd hh:mm):')

        try:
            posts = self._server.get_posts(subject, min_date, max_date)
        except Fault as ex:
            print(get_message(ex))

            return

        print()

        print(format_posts(posts))
Пример #7
0
    def _perform_login(self):
        user_id = ask_user('User identification:')

        try:
            is_registered = self._server.is_user_registered(user_id)
        except Fault as ex:
            print(get_message(ex))

            return

        if is_registered:
            self._user_id = user_id
        else:
            print('Unknown user')
            self._user_id = None
Пример #8
0
    def _print_subjects(self):
        try:
            subjects = self._server.get_subjects(self._user_id)
        except Fault as ex:
            print(get_message(ex))

            return

        def format_subject(subject):
            mask = 'Name: {0}\nPosts limit: {1}'

            return mask.format(
                subject['name'],
                subject['posts_limit']
            )

        print(*map(format_subject, subjects), sep='\n\n')