Last active
March 12, 2019 02:05
-
-
Save billdeitrick/903f705ddd78c85d41e6c78ca4b8ed74 to your computer and use it in GitHub Desktop.
Example scripts using PyPCO.
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
""" | |
This sample script demonstrates how to iterate through the people | |
objects in a list and pull their giving records for a specific fund. | |
""" | |
import pypco | |
### Constants (change these for your environment) ### | |
# App IDs and Secrets | |
APP_ID = '12345' | |
APP_SECRET = '12345' | |
# List ID from which people will be retrieved | |
LIST_ID = 12345 | |
# Fund ID for donations that should be counted | |
FUND_ID = 12345 | |
### End Constants ### | |
# Initialize pypco using a personal access token | |
pco = pypco.PCO(APP_ID, APP_SECRET) | |
# Retrieve the people list needed using the list ID | |
people_list = pco.people.lists.get(LIST_ID) | |
# Iterate through people in the list | |
for person in people_list.rel.people.list(): | |
# Get the equivalent person object from the giving API | |
g_person = pco.giving.people.get(person.id) | |
# Get the donations associated with the person | |
for donation in g_person.rel.donations.list(): | |
# Iterate through the designations associated with the donation | |
for designation in donation.rel.designations.list(): | |
# Check if we've got a designation with the right fund | |
# If we do, we can output and break out of our designations loop | |
if int(designation.rel.fund.get().id) == FUND_ID: | |
print("Found donation from {} ({}) for ${:.2f} to the specified fund.".format(person.name, person.id, designation.amount_cents/100)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment