Created
January 29, 2023 07:41
-
-
Save neoascetic/ec70f564643a68842ff286f4304bf92c to your computer and use it in GitHub Desktop.
Get patron emails from Patreon
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 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