Skip to content

Commit

Permalink
Apply black code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseWeinstein committed Jan 3, 2023
1 parent effc560 commit 46666e9
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions src/tootstream/toot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
from collections import OrderedDict
import webbrowser

# Get the version of Tootstream
import pkg_resources # part of setuptools
import click
Expand Down Expand Up @@ -1982,62 +1983,76 @@ def listaccounts(mastodon, rest):
def listdifference(mastodon, rest):
"""Remove users in the second list from the first list.
ex: listdifference list_to_remove_from list_of_what_to_remove"""
if not(list_support(mastodon)):
if not (list_support(mastodon)):
return
if not rest:
cprint("Argument required.", fg('red'))
cprint("Argument required.", fg("red"))
return
items = rest.split(' ')
items = rest.split(" ")
if len(items) < 2:
cprint("Not enough arguments.", fg('red'))
cprint("Not enough arguments.", fg("red"))
return
list_id = get_list_id(mastodon, items[0])
diff_list_id = get_list_id(mastodon, items[1])

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))]
existing_ids = [
x["id"] for x in mastodon.fetch_remaining(mastodon.list_accounts(list_id))
]

for user in list_accounts:
if user['id'] in existing_ids:
cprint("User {} already missing from list {}.".format(
format_username(user), items[0]), fg('green'))
if user["id"] in existing_ids:
cprint(
"User {} already missing from list {}.".format(
format_username(user), items[0]
),
fg("green"),
)
else:
mastodon.list_accounts_delete(list_id, user['id'])
cprint("Removed {} from list {}.".format(
format_username(user), items[0]), fg('green'))
mastodon.list_accounts_delete(list_id, user["id"])
cprint(
"Removed {} from list {}.".format(format_username(user), items[0]),
fg("green"),
)


@command("<list> <list>", "List")
def listunion(mastodon, rest):
"""Add users in the second list to the first list.
ex: listunion list_to_add_to list_of_what_to_add"""
if not(list_support(mastodon)):
if not (list_support(mastodon)):
return
if not rest:
cprint("Argument required.", fg('red'))
cprint("Argument required.", fg("red"))
return
items = rest.split(' ')
items = rest.split(" ")
if len(items) < 2:
cprint("Not enough arguments.", fg('red'))
cprint("Not enough arguments.", fg("red"))
return
list_id = get_list_id(mastodon, items[0])
if items[1] == "[following]":
user = mastodon.account_verify_credentials()
list_accounts = mastodon.fetch_remaining(mastodon.account_following(user['id']))
list_accounts = mastodon.fetch_remaining(mastodon.account_following(user["id"]))
else:
union_list_id = get_list_id(mastodon, items[1])
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))]
existing_ids = [
x["id"] for x in mastodon.fetch_remaining(mastodon.list_accounts(list_id))
]

for user in list_accounts:
if user['id'] in existing_ids:
cprint("User {} already on list {}.".format(
format_username(user), items[0]), fg('green'))
if user["id"] in existing_ids:
cprint(
"User {} already on list {}.".format(format_username(user), items[0]),
fg("green"),
)
else:
mastodon.list_accounts_add(list_id, user['id'])
cprint("Added {} to list {}.".format(
format_username(user), items[0]), fg('green'))
mastodon.list_accounts_add(list_id, user["id"])
cprint(
"Added {} to list {}.".format(format_username(user), items[0]),
fg("green"),
)


@command("<list> <user>", "List")
Expand Down

0 comments on commit 46666e9

Please sign in to comment.