Exemple #1
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:
        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')))
Exemple #2
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')))