Add --visibility option to post command
This commit is contained in:
parent
9b861ec9cc
commit
3864563520
3 changed files with 16 additions and 4 deletions
|
@ -73,3 +73,9 @@ To post a new status to your timeline:
|
|||
Optionally attach an image or video to the status:
|
||||
|
||||
toot post "Hello world!" --media=path/to/world.jpg
|
||||
|
||||
To set post visibility:
|
||||
|
||||
toot post "Hello world!" --visibility=unlisted
|
||||
|
||||
Possible visibility values are: ``public`` (default), ``unlisted``, ``private``, ``direct``. They are documented `here <https://github.com/tootsuite/documentation/blob/aa20089756c8cf9ff5a52fb35ad1a9472f10970c/Using-Mastodon/User-guide.md#toot-privacy>`_.
|
||||
|
|
|
@ -7,10 +7,8 @@ from requests import Request, Session
|
|||
App = namedtuple('App', ['base_url', 'client_id', 'client_secret'])
|
||||
User = namedtuple('User', ['username', 'access_token'])
|
||||
|
||||
APP_NAME = 'toot'
|
||||
DEFAULT_INSTANCE = 'mastodon.social'
|
||||
|
||||
|
||||
logger = logging.getLogger('toot')
|
||||
|
||||
|
||||
|
@ -94,10 +92,11 @@ def login(app, username, password):
|
|||
return User(username, access_token)
|
||||
|
||||
|
||||
def post_status(app, user, status, media_ids=None):
|
||||
def post_status(app, user, status, visibility='public', media_ids=None):
|
||||
return _post(app, user, '/api/v1/statuses', {
|
||||
'status': status,
|
||||
'media_ids[]': media_ids,
|
||||
'visibility': visibility,
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -145,19 +145,26 @@ def cmd_post_status(app, user):
|
|||
parser.add_option("-m", "--media", dest="media", type="string",
|
||||
help="path to the media file to attach")
|
||||
|
||||
parser.add_option("-v", "--visibility", dest="visibility", type="string", default="public",
|
||||
help='post visibility, either "public" (default), "direct", "private", or "unlisted"')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if len(args) < 2:
|
||||
parser.print_help()
|
||||
raise ConsoleError("No text given")
|
||||
|
||||
if options.visibility not in ['public', 'unlisted', 'private', 'direct']:
|
||||
raise ConsoleError("Invalid visibility value given: '{}'".format(options.visibility))
|
||||
|
||||
if options.media:
|
||||
media = do_upload(app, user, options.media)
|
||||
media_ids = [media['id']]
|
||||
else:
|
||||
media_ids = None
|
||||
|
||||
response = post_status(app, user, args[1], media_ids=media_ids)
|
||||
response = post_status(
|
||||
app, user, args[1], media_ids=media_ids, visibility=options.visibility)
|
||||
|
||||
print("Toot posted: " + green(response.get('url')))
|
||||
|
||||
|
|
Loading…
Reference in a new issue