Skip to content

Instantly share code, notes, and snippets.

@neoascetic
Created January 29, 2023 07:41
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 neoascetic/ec70f564643a68842ff286f4304bf92c to your computer and use it in GitHub Desktop.
Save neoascetic/ec70f564643a68842ff286f4304bf92c to your computer and use it in GitHub Desktop.
Get patron emails from Patreon
import json
import requests
API_TOKEN = 'XXX'
CAMPAIGN_ID = 'XXX'
def get_page(url, headers):
result = requests.get(url, headers=headers)
result.raise_for_status()
return result.json()
def download_members():
users = []
headers = {'Authorization': f'Bearer {API_TOKEN}'}
next_page = f'https://www.patreon.com/api/oauth2/v2/campaigns/{CAMPAIGN_ID}/members?fields[member]=email,patron_status'
while next_page is not None:
result = get_page(next_page, headers)
users += result['data']
next_page = result['meta']['pagination']['cursors']['next']
return users
if __name__ == '__main__':
all = download_members()
attributes = [u['attributes'] for u in all]
active = [
u for u in attributes
if u['patron_status'] in ('active_patron', 'declined_patron')]
emails = [u['email'] for u in active]
print(json.dumps(list(emails)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment