示例#1
0
文件: app.py 项目: l-n-s/toot
    def reply(self):
        """Reply to the selected status"""
        status = self.get_selected_status()
        app, user = self.app, self.user
        if not app or not user:
            self.footer.draw_message("You must be logged in to reply",
                                     Color.RED)
            return

        compose_modal = ComposeModal(
            self.stdscr,
            default_cw='\n'.join(status['spoiler_text']) or None,
            resize_callback=self.on_resize)
        content, cw = compose_modal.loop()
        self.full_redraw()
        if content is None:
            return
        elif len(content) == 0:
            self.footer.draw_message("Status must contain content", Color.RED)
            return

        self.footer.draw_message("Submitting reply...", Color.YELLOW)
        response = api.post_status(app,
                                   user,
                                   content,
                                   spoiler_text=cw,
                                   sensitive=cw is not None,
                                   in_reply_to_id=status['id'])
        status = parse_status(response)
        self.statuses.insert(0, status)
        self.selected += 1
        self.left.draw_statuses(self.statuses, self.selected)
        self.footer.draw_message("✓ Reply posted", Color.GREEN)
示例#2
0
文件: commands.py 项目: mugcake/toot
def post(app, user, args):
    if args.media:
        media = _do_upload(app, user, args.media)
        media_ids = [media['id']]
    else:
        media = None
        media_ids = None

    if media and not args.text:
        args.text = media['text_url']

    if not args.text:
        print_out(
            "Write or paste your toot. Press <yellow>{}</yellow> to post it.".
            format(EOF_KEY))
        args.text = multiline_input()

    if not args.text:
        raise ConsoleError("You must specify either text or media to post.")

    response = api.post_status(
        app,
        user,
        args.text,
        visibility=args.visibility,
        media_ids=media_ids,
        sensitive=args.sensitive,
        spoiler_text=args.spoiler_text,
        in_reply_to_id=args.reply_to,
    )

    print_out("Toot posted: <green>{}</green>".format(response.get('url')))
示例#3
0
文件: app.py 项目: l-n-s/toot
    def compose(self):
        """Compose and submit a new status"""
        app, user = self.app, self.user
        if not app or not user:
            self.footer.draw_message("You must be logged in to post",
                                     Color.RED)
            return

        compose_modal = ComposeModal(self.stdscr,
                                     resize_callback=self.on_resize)
        content, cw = compose_modal.loop()
        self.full_redraw()
        if content is None:
            return
        elif len(content) == 0:
            self.footer.draw_message("Status must contain content", Color.RED)
            return

        self.footer.draw_message("Submitting status...", Color.YELLOW)
        response = api.post_status(app,
                                   user,
                                   content,
                                   spoiler_text=cw,
                                   sensitive=cw is not None)
        status = parse_status(response)
        self.statuses.insert(0, status)
        self.selected += 1
        self.left.draw_statuses(self.statuses, self.selected)
        self.footer.draw_message("✓ Status posted", Color.GREEN)
示例#4
0
    def post_status(self, content, warning, visibility, in_reply_to_id):
        data = api.post_status(self.app, self.user, content,
            spoiler_text=warning,
            visibility=visibility,
            in_reply_to_id=in_reply_to_id)
        status = self.make_status(data)

        # TODO: instead of this, fetch new items from the timeline?
        self.timeline.prepend_status(status)
        self.timeline.focus_status(status)

        self.footer.set_message("Status posted {} \\o/".format(status.id))
        self.close_overlay()
示例#5
0
def post(app, user, args):
    if args.media:
        media = _do_upload(app, user, args.media)
        media_ids = [media['id']]
    else:
        media_ids = None

    response = api.post_status(app,
                               user,
                               args.text,
                               media_ids=media_ids,
                               visibility=args.visibility)

    print_out("Toot posted: <green>{}</green>".format(response.get('url')))
示例#6
0
def post(app, user, args):
    if args.media:
        media = _do_upload(app, user, args.media)
        media_ids = [media['id']]
    else:
        media = None
        media_ids = None

    if media and not args.text:
        args.text = media['text_url']

    if not args.text:
        raise ConsoleError("You must specify either text or media to post.")

    response = api.post_status(app, user, args.text, args.visibility, media_ids)

    print_out("Toot posted: <green>{}</green>".format(response.get('url')))
示例#7
0
def post(app, user, args):
    # TODO: this might be achievable, explore options
    if args.editor and not sys.stdin.isatty():
        raise ConsoleError("Cannot run editor if not in tty.")

    if args.media and len(args.media) > 4:
        raise ConsoleError("Cannot attach more than 4 files.")

    # Read any text that might be piped to stdin
    if not args.text and not sys.stdin.isatty():
        args.text = sys.stdin.read().rstrip()

    if args.media:
        media = [_do_upload(app, user, file) for file in args.media]
        media_ids = [m["id"] for m in media]
    else:
        media = None
        media_ids = None

    if media and not args.text:
        args.text = "\n".join(m['text_url'] for m in media)

    if args.editor:
        args.text = editor_input(args.editor, args.text)
    elif not args.text:
        print_out(
            "Write or paste your toot. Press <yellow>{}</yellow> to post it.".
            format(EOF_KEY))
        args.text = multiline_input()

    if not args.text:
        raise ConsoleError("You must specify either text or media to post.")

    response = api.post_status(
        app,
        user,
        args.text,
        visibility=args.visibility,
        media_ids=media_ids,
        sensitive=args.sensitive,
        spoiler_text=args.spoiler_text,
        in_reply_to_id=args.reply_to,
        language=args.language,
    )

    print_out("Toot posted: <green>{}</green>".format(response.get('url')))
示例#8
0
def cmd_post_status(app, user, args):
    parser = ArgumentParser(prog="toot post",
                            description="Post a status text to the timeline",
                            epilog="https://github.com/ihabunek/toot")
    parser.add_argument("text", help="The status text to post.")
    parser.add_argument("-m", "--media", type=FileType('rb'),
                        help="path to the media file to attach")
    parser.add_argument("-v", "--visibility", type=visibility, default="public",
                        help='post visibility, either "public" (default), "direct", "private", or "unlisted"')

    args = parser.parse_args(args)

    if args.media:
        media = do_upload(app, user, args.media)
        media_ids = [media['id']]
    else:
        media_ids = None

    response = api.post_status(app, user, args.text, media_ids=media_ids, visibility=args.visibility)

    print("Toot posted: " + green(response.get('url')))