Skip to content

Instantly share code, notes, and snippets.

@d3cline
Last active March 25, 2023 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d3cline/c31beed644f1da87c7c7f427fbca5419 to your computer and use it in GitHub Desktop.
Save d3cline/c31beed644f1da87c7c7f427fbca5419 to your computer and use it in GitHub Desktop.
mastodon account note spider (all connected peers)
import requests
# What you want to search, lower case
SEARCH_TERM = "birdsite"
# Your home instance URL
INSTANCE_URL="https://opalstack.social"
# Number of accounts to search before stop
MAX_OFFSET = 10000
def grab_instance_domains():
return requests.get(url=f'{INSTANCE_URL}/api/v1/instance/peers').json()
def spider(domains):
for domain in domains:
CURRENT_OFFSET = 0
while CURRENT_OFFSET < MAX_OFFSET:
try: r = requests.get(url=f'https://{domain}/api/v1/directory?offset={CURRENT_OFFSET}').json()
except Exception as ex:
print(f'domain {domain} faild {ex}')
break
for account in r:
try:
if SEARCH_TERM in account['note'].lower(): print(account['acct'])
except Exception as ex:
print(f'domain {domain} faild {ex}')
break
CURRENT_OFFSET += 40
def main():
print(f'SEARCHING FOR {SEARCH_TERM}')
domains = grab_instance_domains()
spider(domains)
if __name__ == "__main__":
main()
@d3cline
Copy link
Author

d3cline commented Dec 13, 2022

To use this file, download it into an OS environment with python 3.7 or above.
Edit the search term.
Execute the file like this,
python spider.py

@d3cline
Copy link
Author

d3cline commented Dec 13, 2022

This file makes hundreds of outbound requests, and takes a long time to run. It is not fit for use within the app. It is a stop gap only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment