Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from mastodon import Mastodon
- import random
- # Configuration: Replace these with appropriate values
- INSTANCE_URL = "https://mastodon.example" # Replace with your Mastodon instance
- ACCESS_TOKEN = "your_access_token" # Replace with a valid access token
- USERNAME = "target_username" # Replace with the username whose follows you want to fetch
- NUM_TO_PRINT = 5 # Adjust to the desired number of random accounts to print
- def get_random_follows(instance_url, access_token, username, num_to_print):
- """Fetch the list of accounts followed by the specified user, shuffle, and return random subset."""
- mastodon = Mastodon(access_token=access_token, api_base_url=instance_url)
- # Get the account ID for the username
- accounts = mastodon.account_search(username, limit=1)
- if not accounts:
- print(f"User '{username}' not found.")
- return []
- user_id = accounts[0]['id']
- # Get the accounts the user follows
- follows = mastodon.account_following(user_id)
- if not follows:
- print("No follows found.")
- return []
- # Extract timeline URLs
- timeline_urls = [f"{instance_url}/@{account['acct']}" for account in follows]
- # Shuffle and select a random subset
- random.shuffle(timeline_urls)
- selected_urls = timeline_urls[:num_to_print]
- return selected_urls
- if __name__ == "__main__":
- random_timelines = get_random_follows(INSTANCE_URL, ACCESS_TOKEN, USERNAME, NUM_TO_PRINT)
- if random_timelines:
- print(f"Random {NUM_TO_PRINT} Follower Timelines:")
- for url in random_timelines:
- print(url)
- else:
- print("No results found or an error occurred.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement