Skip to content

Instantly share code, notes, and snippets.

@claudinec
Created August 26, 2023 08:19
Show Gist options
  • Save claudinec/fb1cf4589335cc05501053f6f2d156c5 to your computer and use it in GitHub Desktop.
Save claudinec/fb1cf4589335cc05501053f6f2d156c5 to your computer and use it in GitHub Desktop.
# Fetch tags followed by one account and follow them from other account.
# Uses Python `toot` client.
argparse --name=mastodon_follow_tags 'f/from=' 't/to=' -- $argv
type -q toot
if test $status -eq 0
set toot_auth_accounts (string match -r "\* .+@.+" (toot auth))
set toot_auth_num (count $toot_auth_accounts)
if test $toot_auth_num -ge 2
set -g mastodon_accounts
for line in $toot_auth_accounts
set -a -g mastodon_accounts (string replace ' ACTIVE' '' (string match -rg "\* (\w+@.+)" $line))
end
set to_tags
for toot_to_tag in (toot tags_followed -u $_flag_to)
string match -raq "\* (?<to_tag>#\w+)" $toot_to_tag
set -a -g to_tags (string lower $to_tag)
end
for toot_from_tag in (toot tags_followed -u $_flag_from)
string match -raq "\* (?<from_tag>#\w+)" $toot_from_tag
if not contains (string lower $from_tag) $to_tags
echo "Following $from_tag ..."
toot tags_follow -u $_flag_to "$from_tag"
end
end
else
# If the number of accounts returned by (toot auth) < 2, this script can't do anything useful.
echo "$toot_auth_num accounts registered with toot"
return 1
end
else
set err_no_toot "Please install toot: pip install toot"
string match -q Darwin (uname -s)
if test $status -eq 0
set -a err_no_toot " or brew install toot"
end
echo $err_no_toot
return 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment