Skip to content

Instantly share code, notes, and snippets.

@d3cline
Last active December 13, 2022 03:38
Show Gist options
  • Save d3cline/17cee5988ffb219feeacde10675b8aac to your computer and use it in GitHub Desktop.
Save d3cline/17cee5988ffb219feeacde10675b8aac to your computer and use it in GitHub Desktop.
Mastodon account note spider (single instance)
import requests
# What you want to search, lower case
SEARCH_TERM = "anthropology"
# Your home instance URL
INSTANCE_URL="https://opalstack.social"
# Number of accounts to search before stop
MAX_OFFSET = 10000
def spider():
CURRENT_OFFSET = 0
while CURRENT_OFFSET < MAX_OFFSET:
r = requests.get(url=f'{INSTANCE_URL}/api/v1/directory?offset={CURRENT_OFFSET}').json()
for account in r:
if SEARCH_TERM in account['note'].lower(): print(account['acct'])
CURRENT_OFFSET += 40
def main():
spider()
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

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