1
0
mirror of https://github.com/ihabunek/toot.git synced 2025-01-03 14:56:37 -05:00

Add --language option to post command

Used to override language detection.
This commit is contained in:
Ivan Habunek 2019-07-30 16:13:29 +02:00
parent e5bba7e9b3
commit a7e4f9d888
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
4 changed files with 23 additions and 4 deletions

View File

@ -5,6 +5,7 @@ Changelog
* Add `toot notifications` to show notifications (thanks @dlax) * Add `toot notifications` to show notifications (thanks @dlax)
* Add posting and replying to curses interface (thanks @Skehmatics) * Add posting and replying to curses interface (thanks @Skehmatics)
* Add `--language` option to `toot post`
**0.21.0 (2019-02-15)** **0.21.0 (2019-02-15)**

View File

@ -92,7 +92,8 @@ def post_status(
media_ids=None, media_ids=None,
sensitive=False, sensitive=False,
spoiler_text=None, spoiler_text=None,
in_reply_to_id=None in_reply_to_id=None,
language=None,
): ):
""" """
Posts a new status. Posts a new status.
@ -110,6 +111,7 @@ def post_status(
'sensitive': str_bool(sensitive), 'sensitive': str_bool(sensitive),
'spoiler_text': spoiler_text, 'spoiler_text': spoiler_text,
'in_reply_to_id': in_reply_to_id, 'in_reply_to_id': in_reply_to_id,
'language': language,
}, headers=headers).json() }, headers=headers).json()

View File

@ -100,6 +100,7 @@ def post(app, user, args):
sensitive=args.sensitive, sensitive=args.sensitive,
spoiler_text=args.spoiler_text, spoiler_text=args.spoiler_text,
in_reply_to_id=args.reply_to, in_reply_to_id=args.reply_to,
language=args.language,
) )
print_out("Toot posted: <green>{}</green>".format(response.get('url'))) print_out("Toot posted: <green>{}</green>".format(response.get('url')))

View File

@ -13,8 +13,19 @@ from toot.output import print_out, print_err
VISIBILITY_CHOICES = ['public', 'unlisted', 'private', 'direct'] VISIBILITY_CHOICES = ['public', 'unlisted', 'private', 'direct']
def language(value):
"""Validates the language parameter"""
if len(value) != 3:
raise ArgumentTypeError(
"Invalid language specified: '{}'. Expected a 3 letter "
"abbreviation according to ISO 639-2 standard.".format(value)
)
return value
def visibility(value): def visibility(value):
"""Validates the visibilty parameter""" """Validates the visibility parameter"""
if value not in VISIBILITY_CHOICES: if value not in VISIBILITY_CHOICES:
raise ValueError("Invalid visibility value") raise ValueError("Invalid visibility value")
@ -275,11 +286,15 @@ POST_COMMANDS = [
}), }),
(["-p", "--spoiler-text"], { (["-p", "--spoiler-text"], {
"type": str, "type": str,
"help": 'text to be shown as a warning before the actual content', "help": "text to be shown as a warning before the actual content",
}), }),
(["-r", "--reply-to"], { (["-r", "--reply-to"], {
"type": int, "type": int,
"help": 'local ID of the status you want to reply to', "help": "local ID of the status you want to reply to",
}),
(["-l", "--language"], {
"type": language,
"help": "ISO 639-2 language code of the toot, to skip automatic detection",
}), }),
], ],
require_auth=True, require_auth=True,