Last active
September 9, 2018 20:23
-
-
Save BrainBlasted/a139b43a5c8aa8f57c298d065e8275d1 to your computer and use it in GitHub Desktop.
Gets the amount of followers/follows a Pleroma user has
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
#!/usr/bin/python | |
# Gets the amount of followers a Pleroma user has. | |
# Also works to get the amount the user follows. | |
import json | |
import requests | |
import sys | |
def get_followers(url): | |
headers = {'Accept': 'application/activity+json'} | |
r = requests.get(url, headers=headers) | |
items = [] | |
loaded_j = json.loads(r.text) | |
total_items = loaded_j["totalItems"] | |
next = loaded_j["first"]["next"] | |
n_items = loaded_j["first"]["orderedItems"] | |
items += n_items | |
while (r.status_code == 200 and len(items) < total_items): | |
r = requests.get(next, headers=headers) | |
loaded_j = json.loads(r.text) | |
next = loaded_j["next"] | |
n_items = loaded_j["orderedItems"] | |
items += n_items | |
for item in items: | |
print(item) | |
get_followers(str(sys.argv[1])) |
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
#!/usr/bin/python | |
# Gets the amount of followers a Pleroma user has. | |
# Also works to get the amount the user follows. | |
# Takes a URL in form https://instan.ce/users/username/followers | |
import json | |
import requests | |
import sys | |
def get_followers(url): | |
headers = {'Accept': 'application/activity+json'} | |
r = requests.get(url, headers=headers) | |
items = [] | |
loaded_j = json.loads(r.text) | |
total_items = loaded_j["totalItems"] | |
next = loaded_j["first"] | |
while (r.status_code == 200 and len(items) < total_items): | |
r = requests.get(next, headers=headers) | |
loaded_j = json.loads(r.text) | |
try: | |
next = loaded_j["next"] | |
except KeyError: | |
break | |
finally: | |
n_items = loaded_j["orderedItems"] | |
items += n_items | |
for item in items: | |
print(item) | |
get_followers(str(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment