Last active
December 13, 2022 03:38
-
-
Save d3cline/17cee5988ffb219feeacde10675b8aac to your computer and use it in GitHub Desktop.
Mastodon account note spider (single instance)
This file contains hidden or 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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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