Created
November 5, 2022 13:58
-
-
Save nicksergeant/92ab6931ea0a322d3f47eb54e945d9b2 to your computer and use it in GitHub Desktop.
Show Mastodon accounts you're hiding reblogs for, and optionally re-show reblogs for all accounts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domain = "mastodon.social" | |
your_account_id = "12345" | |
bearer_token = "Find this in Chrome Developer Tools -> Network -> an API request -> Headers -> Request Headers -> Authorization" | |
headers = [ | |
Accept: "application/json", | |
"content-type": "application/json", | |
Authorization: "Bearer #{bearer_token}" | |
] | |
IO.puts("Fetching accounts you're following...") | |
following_accounts = | |
HTTPoison.get!( | |
"https://#{domain}/api/v1/accounts/#{your_account_id}/following?limit=10000", | |
headers | |
).body | |
|> Jason.decode!() | |
IO.puts("Fetching your relationships for those accounts...") | |
following_ids = following_accounts |> Enum.map(& &1["id"]) | |
following_relationships = | |
HTTPoison.get!( | |
"https://#{domain}/api/v1/accounts/relationships?#{following_ids |> Enum.join("&id[]=")}", | |
headers | |
).body | |
|> Jason.decode!() | |
hiding_reblogs_accounts = | |
following_relationships | |
|> Enum.filter(&(&1["showing_reblogs"] == false)) | |
|> Enum.map(fn r -> Enum.find(following_accounts, &(&1["id"] == r["id"])) end) | |
hiding_reblogs_names = | |
hiding_reblogs_accounts | |
|> Enum.map(& &1["display_name"]) | |
IO.puts(""" | |
You're hiding reblogs from #{Enum.count(hiding_reblogs_names)} accounts: | |
- #{hiding_reblogs_names |> Enum.join("\n- ")} | |
""") | |
input = | |
IO.gets("Press return to re-enable reblogs from all accounts, or input anything else to exit: ") | |
if input == "\n" do | |
Enum.each(hiding_reblogs_accounts, fn account -> | |
IO.puts("Re-enabling reblogs for #{account["display_name"]}...") | |
HTTPoison.post!( | |
"https://#{domain}/api/v1/accounts/#{account["id"]}/follow", | |
Jason.encode!(%{reblogs: true}), | |
headers | |
) | |
end) | |
end |
Author
nicksergeant
commented
Nov 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment