예제 #1
0
    def test_render_post(self):
        post_obj = {
            'post': {
                'author': {
                    'login': '******'
                },
                'comments_count': 3,
                'created': '2016-08-31T18:54:14.543343',
                'text': 'test message\nnewline',
                'tags': ['foo', 'bar', 'baz baz baz'],
                'type': 'post',
                'private': False,
                'pinned': False,
                'id': 'foobaz'
            },
            'subscribed': True,
            'recommended': False,
            'bookmarked': False,
            'editable': False
        }

        post_txt = """@test_user:
*foo, bar, baz baz baz

test message
newline

#foobaz created at 2016-08-31T18:54:14.543343
Comments: 3"""

        self.assertEqual(render('post', post_obj), post_txt)
예제 #2
0
    def post(self, post, replies=False):
        post_ = post[1:] if post.startswith('#') else post

        res = self._api.get_post(post_)

        print(render('post', res))

        if replies and res['post']['comments_count']:
            self.render_comments(res['comments'])
예제 #3
0
    def test_basic(self):
        p = BlogPost(text='foo', tags=['tag 1', 'tag 2'])

        expected = """------
*tag 1, tag 2

foo
------"""

        self.assertEqual(render('pre_post_preview', {'post': p}), expected)
예제 #4
0
    def test_private(self):
        p = BlogPost(text='foo',
                     tags=['tag 1', 'tag 2', 'tag', 'tag'],
                     private=True)

        expected = """---PRIVATE POST---
*tag 1, tag 2, tag, tag

foo
---PRIVATE POST---"""

        self.assertEqual(render('pre_post_preview', {'post': p}), expected)
예제 #5
0
    def feed(self, f=None):
        if f is None:
            f = self._api.feed

        res = f()

        ps = res['posts']

        if not len(ps):
            print("Sorry, no feed for you")
            sys.exit(0)

        for p in ps:
            print(render('post', p))
            print("\n")
예제 #6
0
    def test_render_with_files(self):
        post_obj = {
            'bookmarked': False,
            'subscribed': False,
            'post': {
                'pinned': False,
                'comments_count': 0,
                'private': False,
                'id': 'ootoot',
                'type': 'post',
                'tags': ['tag'],
                'text': 'Text.',
                'author': {
                    'login': '******'
                },
                'created': '2016-09-02T21:24:20.031391',
                'files': [
                    'http://i.point.im/some/image/1.jpg',
                    'http://i.point.im/some/image/2.jpg'
                ]
            },
            'editable': True,
            'recommended': False,
            'rec': {
                'author': {
                    'login': '******'
                },
                'text': None,
                'comment_id': None
            }
        }

        post_txt = """Recommended by @Otash
@Babuf:
*tag

Text.

http://i.point.im/some/image/1.jpg
http://i.point.im/some/image/2.jpg

#ootoot created at 2016-09-02T21:24:20.031391
Comments: 0"""

        self.assertEqual(render('post', post_obj), post_txt)
예제 #7
0
    def test_render_post_with_text_rec(self):
        post2_obj = {
            'editable': False,
            'rec': {
                'author': {
                    'login': '******',
                },
                'text': 'всё',
                'comment_id': 1
            },
            'recommended': False,
            'bookmarked': False,
            'post': {
                'pinned': False,
                'tags': ['tag@tag', 'tag'],
                'comments_count': 5,
                'text': 'test message\nnewline\n\nnewline',
                'created': '2016-09-02T11:41:13.598825',
                'private': False,
                'type': 'post',
                'id': 'oowqat',
                'author': {
                    'login': '******',
                }
            },
            'subscribed': False
        }

        post2_txt = """Recommended by @NokitaKaze as #oowqat/1: всё
@LambdaFM:
*tag@tag, tag

test message
newline

newline

#oowqat created at 2016-09-02T11:41:13.598825
Comments: 5"""

        self.assertEqual(render('post', post2_obj), post2_txt)
예제 #8
0
    def test_render_with_empty_rec(self):
        post3_obj = {
            'editable': False,
            'rec': {
                'author': {
                    'login': '******',
                },
                'text': None,
                'comment_id': None
            },
            'recommended': False,
            'comment_id': 65,
            'bookmarked': False,
            'post': {
                'pinned': False,
                'tags': ['dybr', 'говно', 'жалкий белок'],
                'comments_count': 83,
                'text': 'блядь. я только понял, что это мой тред. какого хуя вы здесь мне тут устроили?',
                'created': '2016-09-02T12:18:48.338050',
                'private': False,
                'type': 'post',
                'id': 'oowqea',
                'author': {
                    'login': '******',
                }
            },
            'subscribed': False
        }

        post3_txt = """Recommended by @cycl0ne
@hirthwork:

блядь. я только понял, что это мой тред. какого хуя вы здесь мне тут устроили?

#oowqea/65 posted at 2016-09-02T12:18:48.338050
Comments: 83"""

        self.assertEqual(render('post', post3_obj), post3_txt)
예제 #9
0
    def post(self, post, fast, yes, draft):

        # do not create ANYTHING if we have yes and fast
        if fast and yes and not draft:
            self._post(post)
            return

        textedit = TextEditor(post)

        with textedit as t:
            if not fast:
                print('Starting text editor...')
                t.run()

            while not yes:
                print('Preview:')
                print(render('pre_post_preview', {'post': t.result()}))

                condition = confirm(
                    text='Done',
                    additional={'e': 'Just give me another try to edit file'})
                if condition == ['y']:
                    break
                elif condition == ['n']:
                    where = t.save()
                    print("\nFinal draft saved as {0}".format(where))
                    return

                t.run()

        post = textedit.result()
        if draft:
            where = textedit.save()
            print("\nFinal draft saved as {0}".format(where))
            print("Draft-only mode, exiting...")
            return

        self._post(post)
예제 #10
0
    def interactive_feed(self, feed_func=None):
        if feed_func is None:
            feed_func = self._api.feed
        before = None
        res = feed_func()

        if not len(res['posts']):
            print("Empty feed, exiting...")
            sys.exit(0)

        prompt = Prompt(case_sensitive=True,
                        allow_multiple=True,
                        text='Type desired actions (or ? for help):')
        prompt.add_action('r',
                          help='Recommend without comment',
                          conflicts=['R'])
        prompt.add_action('R', help='Recommend with comment', conflicts=['r'])
        prompt.add_action('f', help='Favorite post')
        prompt.add_action('u',
                          help='After all actions unsub from the post',
                          conflicts=['s'])
        prompt.add_action('s', help='Subscribe to post', conflicts=['u'])
        prompt.add_action('c', help='Open editor to leave comment')
        prompt.add_action('n', help='Next post', conflicts=['p'])
        prompt.add_action('p', help='Previous post', conflicts=['n'])
        prompt.add_action('q', help='After all, quit')

        ps = res['posts']
        i = 0
        api = self._api.clone(sysexit=False)
        while True:
            print('=' * 10)
            print(render('post', ps[i]))
            print('=' * 10)
            choice = prompt.input()
            pid = ps[i]['post']['id']

            try:
                if 'f' in choice:
                    api.fav_post(pid)

                if 'r' in choice:
                    api.rec_post(pid)
                elif 'R' in choice:
                    # TODO FIXME
                    raise Exception('Not implemented')
                    r_text = misc.runEditor(ask_user=True)
                    if r_text == "":
                        print("Empty text field")
                        api.rec_post(pid)
                    else:
                        api.rec_post(pid, r_text)

                if 'c' in choice:
                    # TODO FIXME
                    raise Exception('Not implemented')
                    c_text = misc.runEditor(ask_user=True)
                    if c_text is None:
                        print("Aborted")
                    else:
                        api.create_comment(pid, c_text)

                if 's' in choice:
                    api.sub_to_post(pid)
                elif 'u' in choice:
                    api.unsub_from_post(pid)

                if 'p' in choice:
                    if i == 0:
                        print("Sorry, but you cannot jump in future")
                    else:
                        i -= 1
                elif 'n' in choice:
                    if i == len(ps) - 1:
                        print("Loading feed...")
                        if not res['has_next']:
                            print("No feed found. Sorry.")

                        res = feed_func(before=ps[i]['uid'])
                        ps.extend(res['posts'])

                    i += 1

                if 'q' in choice:
                    print("Bye!")
                    break
            except ApiException:
                print('Something went wrong during one of your actions')
                print('=' * 10)
                traceback.print_exc()
                print('=' * 10)
                print('\nYou can continue your actions.')
                continue