Skip to content

Instantly share code, notes, and snippets.

@BrainBlasted
Last active September 9, 2018 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrainBlasted/a139b43a5c8aa8f57c298d065e8275d1 to your computer and use it in GitHub Desktop.
Save BrainBlasted/a139b43a5c8aa8f57c298d065e8275d1 to your computer and use it in GitHub Desktop.
Gets the amount of followers/follows a Pleroma user has
#!/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]))
#!/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