Exemple #1
0
        pass

    def favorite(self, objs, unfavorite=False):
        for o in args['object']:
            text = None
            if args['editor']:
                text = misc.runEditor()
            splitted = o.split('/')
            if len(splitted) > 2:
                print('Invalid post id:', o)
                sys.exit(1)

            {
                1: self._api.fav_post,
                2: self._api.fav_comment
            }[len(splitted)](*splitted, text)

    def sync(self):
        pass

    def show(self):
        pass

kobato_plugin_register(
    'favorite',
    KobatoFavorite,
    aliases=['f', 'fav'],
    description="Manage your favorites",
    default_aliases={'ufav': 'fav -U'}
)
Exemple #2
0
            (False, True): self._api.sub_to_user_recs,
            (True, True): self._api.unsub_from_user_recs
        }[(args['unsub'], args['recs'])]

        do_with_thread = self._api.sub_to_post if not args[
            'unsub'] else self._api.unsub_from_post

        for user in args['user']:
            user_ = user[1:] if user.startswith('@') else user
            print("{} @{}'s {}".format(
                'Subscribing to' if not args['unsub'] else
                'Unsubscribing from', user_, 'posts and recommendations'
                if not args['recs'] else 'recommendations ONLY'))
            result = do_with_user(user_)
            print("Subscribed" if not args['unsub'] else "Unsubscribed")

        for thread in args['post']:
            thread_ = thread[1:] if thread.startswith('#') else thread
            print('{} #{}...'.format(
                'Subscribing to'
                if not args['unsub'] else 'Unsubscribing from', thread_))
            result = do_with_thread(thread_)
            print("Subscribed" if not args['unsub'] else "Unsubscribed")


kobato_plugin_register(
    'subscribe',
    KobatoSubscribe,
    aliases=['s', 'sub'],
    description="Manage your subscriptions to posts, users and tags")
Exemple #3
0
            help=
            'Force run editor if you have disabled it (recommend.show_editor)')
        parser.add_argument('-f',
                            '--fast',
                            action='store_true',
                            help='Supress editor if you have enabled it')
        parser.add_argument('-y',
                            '--yes',
                            action='store_true',
                            help='Do not ask for confirmation')
        parser.add_argument(
            'object',
            nargs='*',
            help='Recommend thread, #thread, #comment/id or comment/id')

        # TODO:
        # add epilogue about choice:
        # either recommend multiple messages without comment,
        # or see editor for each one of them. OR supply len(args['message']) == len(args['object'])
        # that highlights problem that user may forgot what post was about
        # maybe add syntax for comments?

    def run(self, args):
        pass


kobato_plugin_register('recommend',
                       KobatoRecommend,
                       aliases=['r', 'rec'],
                       description="Recommend and unrecommend posts/comments")
Exemple #4
0
        print('Comment to #{}:'.format('/'.join(to)))
        print('=' * 10)
        print(message)
        print('=' * 10)

        y = confirm(text='Confirm?')

        if y != ['y']:
            print('Skipping...')
            return

        res = None

        if len(to) == 1:
            res = self._api.create_comment(to[0], message)
        elif len(to) == 2:
            res = self._api.create_comment(to[0], message, to[1])
        else:
            print('Invalid post/comment ID. Exiting.')
            sys.exit(1)

        print('Comment #{}/{} has been posted'.format(res['id'],
                                                      res['comment_id']))


kobato_plugin_register('comment',
                       KobatoComment,
                       aliases=['c'],
                       description="Write comments and edit them")
Exemple #5
0
        def error(*args, **kwargs):
            print('Invalid format')
            sys.exit(1)

        {
            1: print_group,
            2: print_line
        }.get(len(path.split('.')), error)(*path.split('.'))

    def reset(self, args):
        try:
            (group, name) = args['name'].split('.')
        except ValueError:
            print('You can\'t reset config group. Reset individual entries.'
                  ' Please provide path in format: <group>.<name>')
            sys.exit(1)

        try:
            del self._config[group][name]
        except KeyError:
            pass

        self._config.dump()


kobato_plugin_register('config',
                       KobatoConfig,
                       aliases=['cfg'],
                       description='Set, reset and view kobato config')
Exemple #6
0
        self._config['login'] = {}
        self._config['login']['token'] = result['token']
        self._config['login']['csrf_token'] = result['csrf_token']
        self._config['login']['login'] = login
        self._config['login']['password'] = password
        self._config['login']['is_logged_in'] = True
        self._config.dump()
        print("Successful authorization. Config file updated")
        print("Welcome, @{0}!".format(login))

    @auth_required
    def reset(self):
        if 'csrf_token' not in self._config['login']:
            print("CSRF token not found, flushing config...")
            self._config.flush()
            self._config.dump()
            return

        res = self._api.logout()

        self._config.flush()
        self._config.dump()
        print("See ya!")


kobato_plugin_register(
    'login',
    KobatoLogin,
    aliases=['lo', 'l'],
    description="Login. Just type your password and use the damn thing.")
Exemple #7
0
        if args['show']:
            print('Showing your current whitelist...')

            print("\n{}'s whitelist:".format(self._api.get_login()))
            wl = self._api.wl()
            if not len(wl):
                print("EMPTY")
                return

            print(", ".join(wl))

            return

        pre_text = "Removing {} from whitelist..." if unwl else "Adding {} to whitelist..."

        for u in args['object']:
            user_ = u[1:] if u.startswith('@') else u
            print(pre_text.format(user_))
            res = wl_func(user_)
            print("Done")


kobato_plugin_register(
    'whitelist',
    KobatoWhitelist,
    aliases=['wl'],
    description="Manage your whitelist",
    default_aliases={'uwl': 'wl -U {...}'}
)
Exemple #8
0
        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)

    def _post(self, post):
        print("Posting...")

        if not post.text:
            print("ERROR: Post body cannot be empty.")
            sys.exit(1)

        result = self._api.create_post(post.text, post.tags, post.private)

        print("Post #{0} successfully created".format(result['id']))


kobato_plugin_register('post',
                       KobatoPost,
                       aliases=['p'],
                       description='Create and send, pin and unpin your posts',
                       default_aliases={
                           'pin': 'post --pin {0}',
                           'unpin': 'post --unpin {0}'
                       })
Exemple #9
0
                "" if res['subscribed'] else "NOT "))
        if f('rec sub'):
            print("You are {0}subscribed to recommendations".format(
                "" if res['rec sub'] else "NOT "))
        if f('wl'):
            print("This user is {0}in your WL".format(
                "" if res['wl'] else "NOT "))

        # TODO format
        print("Created:", res['created'])
        if res['deny_anonymous']:
            print("This blog is for registered users only")
        if res['private']:
            print("This blog is protected by whitelist")

    def gender_to_str(self, gender):
        if gender is None:
            return "Ugnich"
        elif gender:
            return "Male"
        else:
            return "Female"


kobato_plugin_register(
    'show',
    KobatoShow,
    description=
    "Get information about users, their last posts, about posts, comments and tags"
)
Exemple #10
0
            if 'aliases' not in self._config:
                self._config['aliases'] = {}

            alias_name = args['create'][0]
            alias_body = args['create'][1]
            if alias_name in self._config['aliases'] and not args['force']:
                print(
                    "ERROR: alias with same name already exists. Use --force to replace or --list to view list of aliases"
                )
                sys.exit(1)

            self._config['aliases'][alias_name] = alias_body
            self._config.dump()
            print("Alias {0} added".format(alias_name))
            return

        if args['delete']:
            alias_name = args['delete']

            if 'aliases' not in self._config or alias_name not in self._config[
                    'aliases']:
                print("Alias {0} not found".format(args['delete']))
                return

            del self._config['aliases'][alias_name]
            self._config.dump()
            print("Alias {0} deleted".format(alias_name))


kobato_plugin_register('alias', KobatoAlias, description="Manage your aliases")
Exemple #11
0
                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


kobato_plugin_register(
    'feed',
    KobatoFeed,
    aliases=['f'],
    description=
    "Read your feed. Es ist an important part of microblogging. Don't forget to read your feed."
)
Exemple #12
0
                            default=False,
                            help='Show your current blacklist')
        parser.add_argument('-u', '--user')
        parser.add_argument(
            '-m',
            '--message',
            help=
            'Add optional message about reasons why you hate him/her/whatever. That message will be stored locally'
        )

        parser.add_argument(
            '-b',
            '--blacklisters',
            action='store_true',
            default=False,
            help='Show users who dared to blacklist your majesty')
        # TODO: edit message (-e?), run editor (eh, another -e? -E?)
        # TODO: maybe allow blacklist multiple at once?

    def run(self, args):
        pass


kobato_plugin_register(
    'blacklist',
    KobatoBlacklist,
    aliases=['bl'],
    description="Add and remove users to/from your blacklist, "
    "view your current blacklist, show users that blacklisted you",
    default_aliases={'ubl': 'bl -U'})
Exemple #13
0
            sys.exit(1)

        def _wtf(entity):
            def func(_):
                print('Invalid post or comment id: #{}'.format(entity))

            return func

        for i in args['object']:
            entity_ = i[1:] if i.startswith('#') else i

            if not args['yes']:
                r = confirm(default='no',
                            text='Deleting #{}. Confirm?'.format(entity_))
                if r == ['n']:
                    print('Leaving it untouched')
                    continue

            res = {
                1: lambda a: a.delete_post(entity_),
                2: lambda a: a.delete_comment(*entity_.split('/'))
            }.get(len(entity_.split('/')), _wtf(entity_))(self._api)

            print("Post #{0} has been removed successfully".format(entity_))


kobato_plugin_register('delete',
                       KobatoDelete,
                       aliases=['d', 'del'],
                       description="Delete your posts or comments")