Skip to content

Instantly share code, notes, and snippets.

@mikicz
Created February 12, 2021 22:07
Show Gist options
  • Save mikicz/710466362d8760f5d232e7689921d217 to your computer and use it in GitHub Desktop.
Save mikicz/710466362d8760f5d232e7689921d217 to your computer and use it in GitHub Desktop.
Get donations breakdown for a tiltify campaign by anonymous/non-anonymous donations
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import requests
# In[2]:
api_token = None # fill in token here!!!
campaign_id = 95460
# In[3]:
donations = {}
url = f"/api/v3/campaigns/{campaign_id}/donations?count=100"
while url:
print(url)
response = requests.get(
"https://tiltify.com" + url,
headers={'Authorization': 'Bearer {}'.format(api_token)}
)
response = response.json()
for row in response["data"]:
donations[row["id"]] = row
url = response["links"]["prev"]
# In[4]:
print("Total donations: ", len(donations))
# In[5]:
print("Example donation entry")
list(donations.values())[0]
# In[6]:
total_count = anonymous_count = 0
total_amount = anonymous_amount = 0
for donation in donations.values():
total_count += 1
total_amount += donation["amount"]
if donation["name"] == "Anonymous":
anonymous_count += 1
anonymous_amount += donation["amount"]
# In[7]:
print("Total donations count:", total_count, "out of that anonymous:", anonymous_count)
# In[8]:
print("Total donations amount:", round(total_amount, 2), "out of that anonymous:", round(anonymous_amount, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment