Skip to content

Commit

Permalink
Enable attaching multiple media files
Browse files Browse the repository at this point in the history
fixes #67
  • Loading branch information
ihabunek committed Aug 1, 2019
1 parent 42247f9 commit a771ca3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
* Add `toot notifications` to show notifications (thanks @dlax)
* Add posting and replying to curses interface (thanks @Skehmatics)
* Add `--language` option to `toot post`
* Enable attaching upto 4 files via `--media` option on `toot post`

**0.21.0 (2019-02-15)**

Expand Down
9 changes: 6 additions & 3 deletions toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ def curses(app, user, args):


def post(app, user, args):
if args.media and len(args.media) > 4:
raise ConsoleError("Cannot attach more than 4 files.")

if args.media:
media = _do_upload(app, user, args.media)
media_ids = [media['id']]
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 = media['text_url']
args.text = "\n".join(m['text_url'] for m in media)

if not args.text:
print_out("Write or paste your toot. Press <yellow>{}</yellow> to post it.".format(EOF_KEY))
Expand Down
6 changes: 4 additions & 2 deletions toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ def timeline_count(value):
"nargs": "?",
}),
(["-m", "--media"], {
"type": FileType('rb'),
"help": "path to the media file to attach"
"action": "append",
"type": FileType("rb"),
"help": "path to the media file to attach (specify multiple "
"times to attach up to 4 files)"
}),
(["-v", "--visibility"], {
"type": visibility,
Expand Down

0 comments on commit a771ca3

Please sign in to comment.