Add status related commands
(un)favourite, (un)reblog & (un)pin. fixes #75
This commit is contained in:
parent
fc57d2695a
commit
82ed630864
6 changed files with 138 additions and 30 deletions
|
@ -6,6 +6,8 @@ Changelog
|
||||||
* Enable interaction with instances using http instead of https (#56)
|
* Enable interaction with instances using http instead of https (#56)
|
||||||
* Enable proxy usage via environment variables (#47)
|
* Enable proxy usage via environment variables (#47)
|
||||||
* Make `toot post` prompt for input if no text is given (#82)
|
* Make `toot post` prompt for input if no text is given (#82)
|
||||||
|
* Add post-related commands: `favourite`, `unfavourite`, `reblog`, `unreblog`,
|
||||||
|
`pin` & `unpin` (#75)
|
||||||
|
|
||||||
**0.19.0 (2018-06-27)**
|
**0.19.0 (2018-06-27)**
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ toot is a commandline tool for interacting with Mastodon social networks.
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
* Posting, replying, deleting statuses
|
* Posting, replying, deleting, favouriting, reblogging & pinning statuses
|
||||||
* Support for media uploads, spoiler text, sensitive content
|
* Support for media uploads, spoiler text, sensitive content
|
||||||
* Search by account or hash tag
|
* Search by account or hash tag
|
||||||
* Following, muting and blocking accounts
|
* Following, muting and blocking accounts
|
||||||
|
|
|
@ -30,7 +30,15 @@ Running ``toot <command> -h`` shows the documentation for the given command.
|
||||||
Post:
|
Post:
|
||||||
toot post Post a status text to your timeline
|
toot post Post a status text to your timeline
|
||||||
toot upload Upload an image or video file
|
toot upload Upload an image or video file
|
||||||
toot delete Delete an existing status
|
|
||||||
|
Status:
|
||||||
|
toot delete Delete a status
|
||||||
|
toot favourite Favourite a status
|
||||||
|
toot unfavourite Unfavourite a status
|
||||||
|
toot reblog Reblog a status
|
||||||
|
toot unreblog Unreblog a status
|
||||||
|
toot pin Pin a status
|
||||||
|
toot unpin Unpin a status
|
||||||
|
|
||||||
Accounts:
|
Accounts:
|
||||||
toot follow Follow an account
|
toot follow Follow an account
|
||||||
|
|
30
toot/api.py
30
toot/api.py
|
@ -17,6 +17,12 @@ def _account_action(app, user, account, action):
|
||||||
return http.post(app, user, url).json()
|
return http.post(app, user, url).json()
|
||||||
|
|
||||||
|
|
||||||
|
def _status_action(app, user, status_id, action):
|
||||||
|
url = '/api/v1/statuses/{}/{}'.format(status_id, action)
|
||||||
|
|
||||||
|
return http.post(app, user, url).json()
|
||||||
|
|
||||||
|
|
||||||
def create_app(domain, scheme='https'):
|
def create_app(domain, scheme='https'):
|
||||||
url = '{}://{}/api/v1/apps'.format(scheme, domain)
|
url = '{}://{}/api/v1/apps'.format(scheme, domain)
|
||||||
|
|
||||||
|
@ -114,6 +120,30 @@ def delete_status(app, user, status_id):
|
||||||
return http.delete(app, user, '/api/v1/statuses/{}'.format(status_id))
|
return http.delete(app, user, '/api/v1/statuses/{}'.format(status_id))
|
||||||
|
|
||||||
|
|
||||||
|
def favourite(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'favourite')
|
||||||
|
|
||||||
|
|
||||||
|
def unfavourite(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'unfavourite')
|
||||||
|
|
||||||
|
|
||||||
|
def reblog(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'reblog')
|
||||||
|
|
||||||
|
|
||||||
|
def unreblog(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'unreblog')
|
||||||
|
|
||||||
|
|
||||||
|
def pin(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'pin')
|
||||||
|
|
||||||
|
|
||||||
|
def unpin(app, user, status_id):
|
||||||
|
return _status_action(app, user, status_id, 'unpin')
|
||||||
|
|
||||||
|
|
||||||
def timeline_home(app, user):
|
def timeline_home(app, user):
|
||||||
return http.get(app, user, '/api/v1/timelines/home').json()
|
return http.get(app, user, '/api/v1/timelines/home').json()
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,39 @@ def post(app, user, args):
|
||||||
|
|
||||||
def delete(app, user, args):
|
def delete(app, user, args):
|
||||||
api.delete_status(app, user, args.status_id)
|
api.delete_status(app, user, args.status_id)
|
||||||
|
|
||||||
print_out("<green>✓ Status deleted</green>")
|
print_out("<green>✓ Status deleted</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def favourite(app, user, args):
|
||||||
|
api.favourite(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status favourited</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def unfavourite(app, user, args):
|
||||||
|
api.unfavourite(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status unfavourited</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def reblog(app, user, args):
|
||||||
|
api.reblog(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status reblogged</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def unreblog(app, user, args):
|
||||||
|
api.unreblog(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status unreblogged</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def pin(app, user, args):
|
||||||
|
api.pin(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status pinned</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def unpin(app, user, args):
|
||||||
|
api.unpin(app, user, args.status_id)
|
||||||
|
print_out("<green>✓ Status unpinned</green>")
|
||||||
|
|
||||||
|
|
||||||
def auth(app, user, args):
|
def auth(app, user, args):
|
||||||
config_data = config.load_config()
|
config_data = config.load_config()
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,10 @@ scheme_arg = (["--disable-https"], {
|
||||||
"const": "http",
|
"const": "http",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
status_id_arg = (["status_id"], {
|
||||||
|
"help": "ID of the status",
|
||||||
|
"type": int,
|
||||||
|
})
|
||||||
|
|
||||||
AUTH_COMMANDS = [
|
AUTH_COMMANDS = [
|
||||||
Command(
|
Command(
|
||||||
|
@ -243,15 +247,49 @@ POST_COMMANDS = [
|
||||||
],
|
],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
STATUS_COMMANDS = [
|
||||||
Command(
|
Command(
|
||||||
name="delete",
|
name="delete",
|
||||||
description="Delete an existing status",
|
description="Delete a status",
|
||||||
arguments=[
|
arguments=[status_id_arg],
|
||||||
(["status_id"], {
|
require_auth=True,
|
||||||
"help": "ID of the status to delete",
|
),
|
||||||
"type": int,
|
Command(
|
||||||
})
|
name="favourite",
|
||||||
],
|
description="Favourite a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="unfavourite",
|
||||||
|
description="Unfavourite a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="reblog",
|
||||||
|
description="Reblog a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="unreblog",
|
||||||
|
description="Unreblog a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="pin",
|
||||||
|
description="Pin a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="unpin",
|
||||||
|
description="Unpin a status",
|
||||||
|
arguments=[status_id_arg],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -307,7 +345,7 @@ ACCOUNTS_COMMANDS = [
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
COMMANDS = AUTH_COMMANDS + READ_COMMANDS + POST_COMMANDS + ACCOUNTS_COMMANDS
|
COMMANDS = AUTH_COMMANDS + READ_COMMANDS + POST_COMMANDS + STATUS_COMMANDS + ACCOUNTS_COMMANDS
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
|
@ -317,6 +355,7 @@ def print_usage():
|
||||||
("Authentication", AUTH_COMMANDS),
|
("Authentication", AUTH_COMMANDS),
|
||||||
("Read", READ_COMMANDS),
|
("Read", READ_COMMANDS),
|
||||||
("Post", POST_COMMANDS),
|
("Post", POST_COMMANDS),
|
||||||
|
("Status", STATUS_COMMANDS),
|
||||||
("Accounts", ACCOUNTS_COMMANDS),
|
("Accounts", ACCOUNTS_COMMANDS),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue