mirror of
https://github.com/ihabunek/toot
synced 2024-12-22 07:01:46 +01:00
Added "toot list_delete" and "toot list_create" commands
This commit is contained in:
parent
08bb7aae71
commit
bfdd84870f
@ -2,3 +2,4 @@ requests>=2.13,<3.0
|
|||||||
beautifulsoup4>=4.5.0,<5.0
|
beautifulsoup4>=4.5.0,<5.0
|
||||||
wcwidth>=0.1.7
|
wcwidth>=0.1.7
|
||||||
urwid>=2.0.0,<3.0
|
urwid>=2.0.0,<3.0
|
||||||
|
|
||||||
|
21
toot/api.py
21
toot/api.py
@ -534,9 +534,18 @@ def find_list_id(app, user, title):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_list_accounts(app, user, title):
|
def get_list_accounts(app, user, list_id):
|
||||||
id = find_list_id(app, user, title)
|
path = f"/api/v1/lists/{list_id}/accounts"
|
||||||
if id:
|
return _get_response_list(app, user, path)
|
||||||
path = "/api/v1/{id}/accounts"
|
|
||||||
return _get_response_list(app, user, path)
|
|
||||||
return []
|
def create_list(app, user, title, replies_policy):
|
||||||
|
url = "/api/v1/lists"
|
||||||
|
json = {'title': title}
|
||||||
|
if replies_policy:
|
||||||
|
json['replies_policy'] = replies_policy
|
||||||
|
return http.post(app, user, url, json=json).json()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_list(app, user, id):
|
||||||
|
return http.delete(app, user, f"/api/v1/lists/{id}")
|
||||||
|
@ -430,8 +430,20 @@ def lists(app, user, args):
|
|||||||
|
|
||||||
|
|
||||||
def list_accounts(app, user, args):
|
def list_accounts(app, user, args):
|
||||||
response = api.get_list_accounts(app, user, args.title)
|
id = args.id if args.id else api.find_list_id(app, user, args.title)
|
||||||
print_list_accounts(args.title[0], response)
|
response = api.get_list_accounts(app, user, id)
|
||||||
|
print_list_accounts(response)
|
||||||
|
|
||||||
|
|
||||||
|
def list_create(app, user, args):
|
||||||
|
api.create_list(app, user, title=args.title, replies_policy=args.replies_policy)
|
||||||
|
print_out(f"<green>✓ List \"{args.title}\" created.</green>")
|
||||||
|
|
||||||
|
|
||||||
|
def list_delete(app, user, args):
|
||||||
|
id = args.id if args.id else api.find_list_id(app, user, args.title)
|
||||||
|
api.delete_list(app, user, id)
|
||||||
|
print_out(f"<green>✓ List \"{args.title}\"</green> <red>deleted.</red>")
|
||||||
|
|
||||||
|
|
||||||
def mute(app, user, args):
|
def mute(app, user, args):
|
||||||
|
@ -727,16 +727,52 @@ TAG_COMMANDS = [
|
|||||||
LIST_COMMANDS = [
|
LIST_COMMANDS = [
|
||||||
Command(
|
Command(
|
||||||
name="lists",
|
name="lists",
|
||||||
description="List all user lists",
|
description="List all lists",
|
||||||
arguments=[],
|
arguments=[],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
name="list_accounts",
|
name="list_accounts",
|
||||||
description="List the accounts in a list",
|
description="List the accounts in a list",
|
||||||
arguments=[
|
arguments=[(["--id"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "ID of the list"
|
||||||
|
}),
|
||||||
|
(["--title"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "title of the list"
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="list_create",
|
||||||
|
description="Create a list",
|
||||||
|
arguments=[
|
||||||
|
(["--id"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "ID of the list"
|
||||||
|
}),
|
||||||
|
(["--title"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "title of the list"
|
||||||
|
}),
|
||||||
|
(["--replies-policy"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "replies policy: 'followed', 'list', or 'none' (defaults to 'none')"
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
require_auth=True,
|
||||||
|
),
|
||||||
|
Command(
|
||||||
|
name="list_delete",
|
||||||
|
description="Delete a list",
|
||||||
|
arguments=[
|
||||||
|
(["--id"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "ID of the list"
|
||||||
|
}),
|
||||||
(["--title"], {
|
(["--title"], {
|
||||||
"action": "append",
|
|
||||||
"type": str,
|
"type": str,
|
||||||
"help": "title of the list"
|
"help": "title of the list"
|
||||||
}),
|
}),
|
||||||
|
@ -92,13 +92,13 @@ def patch(app, user, path, headers=None, files=None, data=None, json=None):
|
|||||||
return process_response(response)
|
return process_response(response)
|
||||||
|
|
||||||
|
|
||||||
def delete(app, user, path, data=None, headers=None):
|
def delete(app, user, path, data=None, json=None, headers=None):
|
||||||
url = app.base_url + path
|
url = app.base_url + path
|
||||||
|
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
headers["Authorization"] = f"Bearer {user.access_token}"
|
headers["Authorization"] = f"Bearer {user.access_token}"
|
||||||
|
|
||||||
request = Request('DELETE', url, headers=headers, json=data)
|
request = Request('DELETE', url, headers=headers, data=data, json=json)
|
||||||
response = send_request(request)
|
response = send_request(request)
|
||||||
|
|
||||||
return process_response(response)
|
return process_response(response)
|
||||||
|
@ -214,15 +214,15 @@ def print_list_list(lists):
|
|||||||
if lists:
|
if lists:
|
||||||
for list_item in lists:
|
for list_item in lists:
|
||||||
replies_policy = list_item['replies_policy'] if list_item['replies_policy'] else ''
|
replies_policy = list_item['replies_policy'] if list_item['replies_policy'] else ''
|
||||||
print_out(f"Name: <green>\"{list_item['title']}\"</green>\t"
|
print_out(f"Title: <green>\"{list_item['title']}\"</green>\t"
|
||||||
+ f"ID: <green>{list_item['id']}\t</green>"
|
+ f"ID: <green>{list_item['id']}\t</green>"
|
||||||
+ f"Replies policy: <green>{replies_policy}</green>")
|
+ f"Replies policy: <green>{replies_policy}</green>")
|
||||||
else:
|
else:
|
||||||
print_out("You have no lists defined.")
|
print_out("You have no lists defined.")
|
||||||
|
|
||||||
|
|
||||||
def print_list_accounts(list_title, accounts):
|
def print_list_accounts(accounts):
|
||||||
print_out(f"Accounts in list <green>\"{list_title}\"</green>:\n")
|
print_out("Accounts in list</green>:\n")
|
||||||
if accounts:
|
if accounts:
|
||||||
print_acct_list(accounts)
|
print_acct_list(accounts)
|
||||||
else:
|
else:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# scroll.py
|
# scroll.py
|
||||||
#
|
#
|
||||||
# Copied from the stig project by rndusr@github
|
# Copied from the stig project by rndusr@github
|
||||||
# https://github.com/rndusr/sti
|
# https://github.com/rndusr/stig
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
Loading…
Reference in New Issue
Block a user