Added "toot list_delete" and "toot list_create" commands

pull/351/head
Daniel Schwarz 2023-03-14 19:14:58 -04:00 zatwierdzone przez Ivan Habunek
rodzic 08bb7aae71
commit bfdd84870f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: CDBD63C43A30BB95
7 zmienionych plików z 75 dodań i 17 usunięć

Wyświetl plik

@ -2,3 +2,4 @@ requests>=2.13,<3.0
beautifulsoup4>=4.5.0,<5.0
wcwidth>=0.1.7
urwid>=2.0.0,<3.0

Wyświetl plik

@ -534,9 +534,18 @@ def find_list_id(app, user, title):
return None
def get_list_accounts(app, user, title):
id = find_list_id(app, user, title)
if id:
path = "/api/v1/{id}/accounts"
return _get_response_list(app, user, path)
return []
def get_list_accounts(app, user, list_id):
path = f"/api/v1/lists/{list_id}/accounts"
return _get_response_list(app, user, path)
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}")

Wyświetl plik

@ -430,8 +430,20 @@ def lists(app, user, args):
def list_accounts(app, user, args):
response = api.get_list_accounts(app, user, args.title)
print_list_accounts(args.title[0], response)
id = args.id if args.id else api.find_list_id(app, user, args.title)
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):

Wyświetl plik

@ -727,16 +727,52 @@ TAG_COMMANDS = [
LIST_COMMANDS = [
Command(
name="lists",
description="List all user lists",
description="List all lists",
arguments=[],
require_auth=True,
),
Command(
name="list_accounts",
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"], {
"action": "append",
"type": str,
"help": "title of the list"
}),

Wyświetl plik

@ -92,13 +92,13 @@ def patch(app, user, path, headers=None, files=None, data=None, json=None):
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
headers = headers or {}
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)
return process_response(response)

Wyświetl plik

@ -214,15 +214,15 @@ def print_list_list(lists):
if lists:
for list_item in lists:
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"Replies policy: <green>{replies_policy}</green>")
else:
print_out("You have no lists defined.")
def print_list_accounts(list_title, accounts):
print_out(f"Accounts in list <green>\"{list_title}\"</green>:\n")
def print_list_accounts(accounts):
print_out("Accounts in list</green>:\n")
if accounts:
print_acct_list(accounts)
else:

Wyświetl plik

@ -1,7 +1,7 @@
# scroll.py
#
# 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
# it under the terms of the GNU General Public License as published by