Skip to content

Commit

Permalink
Remove redundant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseWeinstein committed Dec 27, 2022
1 parent 531009c commit 3a041a8
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions src/tootstream/toot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ def listaccounts(mastodon, rest):
for user in list_accounts:
printUser(user)


listaccounts.__argstr__ = '<list>'
listaccounts.__section__ = 'List'

Expand All @@ -2099,13 +2100,7 @@ def listdifference(mastodon, rest):
cprint("Not enough arguments.", fg('red'))
return
list_id = get_list_id(mastodon, items[0])
if not list_id:
cprint("List {} is not found".format(items[0]), fg('red'))
return
diff_list_id = get_list_id(mastodon, items[1])
if not diff_list_id:
cprint("List {} is not found".format(items[1]), fg('red'))
return

list_accounts = mastodon.fetch_remaining(mastodon.list_accounts(diff_list_id))
existing_ids = [x['id'] for x in mastodon.fetch_remaining(mastodon.list_accounts(list_id))]
Expand All @@ -2115,13 +2110,9 @@ def listdifference(mastodon, rest):
cprint("User {} already missing from list {}.".format(
format_username(user), items[0]), fg('green'))
else:
try:
mastodon.list_accounts_delete(list_id, user['id'])
cprint("Removed {} from list {}.".format(
format_username(user), items[0]), fg('green'))
except Exception as e:
cprint("error while deleting from list: {}".format(
type(e).__name__), fg('red'))
mastodon.list_accounts_delete(list_id, user['id'])
cprint("Removed {} from list {}.".format(
format_username(user), items[0]), fg('green'))


listdifference.__argstr__ = '<list> <list>'
Expand All @@ -2141,18 +2132,11 @@ def listunion(mastodon, rest):
cprint("Not enough arguments.", fg('red'))
return
list_id = get_list_id(mastodon, items[0])
if not list_id:
cprint("List {} is not found".format(items[0]), fg('red'))
return
if items[1] == "[following]":
user = mastodon.account_verify_credentials()
list_accounts = mastodon.fetch_remaining(mastodon.account_following(user['id']))
else:
union_list_id = get_list_id(mastodon, items[1])
if not union_list_id:
cprint("List {} is not found".format(items[1]), fg('red'))
return

list_accounts = mastodon.fetch_remaining(mastodon.list_accounts(union_list_id))

existing_ids = [x['id'] for x in mastodon.fetch_remaining(mastodon.list_accounts(list_id))]
Expand All @@ -2162,13 +2146,9 @@ def listunion(mastodon, rest):
cprint("User {} already on list {}.".format(
format_username(user), items[0]), fg('green'))
else:
try:
mastodon.list_accounts_add(list_id, user['id'])
cprint("Added {} to list {}.".format(
format_username(user), items[0]), fg('green'))
except Exception as e:
cprint("error while adding to list: {}".format(
type(e).__name__), fg('red'))
mastodon.list_accounts_add(list_id, user['id'])
cprint("Added {} to list {}.".format(
format_username(user), items[0]), fg('green'))


listunion.__argstr__ = '<list> <list>'
Expand Down

0 comments on commit 3a041a8

Please sign in to comment.