Last active
July 1, 2020 07:22
-
-
Save kylemsguy/0aba59be3cab211cc75bdc335bc30394 to your computer and use it in GitHub Desktop.
Get useful Indiegogo backer data and save it as a json
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 | |
if __name__ == "__main__": | |
name = input("Enter your Indiegogo Pledge display name: ") | |
with open('backer_data.json') as infile: | |
data = json.load(infile) | |
backers = data['backers'] | |
for i in range(len(backers)): | |
if backers[i]['pledger_display_name'] == name: | |
print(len(backers) - i) | |
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 time | |
import json | |
import requests | |
campaign_id = 0 # integer | |
api_url = "https://www.indiegogo.com/private_api/campaigns/{campaign_id}/pledges?page={page_no}" | |
def get_backer_data(data: dict) -> list: | |
""" | |
Get backer data | |
""" | |
current_time = time.time() | |
backers = [] | |
for item in data['response']: | |
# backer = { | |
# 'name': item['pledger_display_name'], | |
# 'profile_url': item['pledger_profile_url'], | |
# 'amount': item['display_amount'], | |
# 'currency': item['display_amount_iso_code'], | |
# } | |
# backers.append(backer) | |
item['request_time'] = current_time | |
backers.append(item) | |
return backers | |
if __name__ == "__main__": | |
start_time = time.time() | |
print("Reading indiegogo backer data...") | |
r = requests.get(api_url.format(campaign_id=campaign_id, page_no=1)) | |
if(r.status_code != requests.codes.ok): | |
print("Error reading from page (status code {})".format(r.status_code)) | |
data = r.json() | |
num_pages = data['pagination']['pages'] | |
print("Preparing to read {} pages".format(num_pages)) | |
backers = [] | |
backers += get_backer_data(data) | |
print("Finished reading page 1") | |
for i in range(2, num_pages+1): | |
r = requests.get(api_url.format(campaign_id=campaign_id, page_no=i)) | |
while r.status_code == 429: | |
print("Rate limit exceeded... Waiting 10 seconds...") | |
time.sleep(10) | |
r = requests.get(api_url.format(campaign_id=campaign_id, page_no=i)) | |
if r.status_code != requests.codes.ok: | |
print("Error reading from page (status code {})".format(r.status_code)) | |
input("Press enter to continue, Ctrl-C to quit") | |
try: | |
backers += get_backer_data(r.json()) | |
except json.JSONDecodeError: | |
print(r.text) | |
print("Finished reading page {}".format(i)) | |
# At this point, backer data is most likely in reverse order | |
end_time = time.time() | |
print("Seconds elapsed: {}".format(end_time - start_time)) | |
with open('backer_data.json', 'w') as out_json: | |
json.dump({ | |
"campaign_id": campaign_id, | |
"start_time": start_time, | |
"end_time": end_time, | |
"backers": backers, | |
}, out_json, indent=4) | |
print("Successfully read {} backers".format(len(backers))) | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Useful campaign IDs include the following:
GPD Win 2: 2313424
GPD Win Max: 2598099