At the finals stages of my Kickstarter Campaign a small issue arose. First, though, a little background. Kickstarter allows the Creator to send out a form to all of the Backers – 1 form for each reward level – to collect data like addresses. That information is in turn returned to the backer in the form of a CSV file that looks some thing like this example (not an actual backer’s info):
Backer Id | Backer Name | Pledge Amount | Name | Line_1 | Line_2 | City | State | Zip Code | List as Sponsor | |
1 | 1_Chip | chip@.com | $10,000 | Bob Backer | 1 Chip Rd | PO Box 1 | Kickville | ATtiny | 2313 | Yes |
There is one CSV file per reward tier:
The issue was that I needed to get only a list of all the backers who had selected “Yes” in response to whether they would like to be on the sponsor page or not. I also needed to get their real Name and not their Backer Name.
I could have gone through each CSV and one by one copy and pasted each Backer’s real name who had selected “Yes” as to whether they would like to be on the list of sponsors page, but there seemed like a better method.
After some quick searching I found that Python had a library to work with CSV files so I wrote this quick and dirty script. It is by no means the best solution to the problem, but it works.
import csv reward_tier = ["earlybacker.csv","letter.csv","basickit.csv","assembledbasic.csv","kitchip.csv","assembledchip.csv","personalized.csv"] # list of CSV files to process def retrieve(documet): name_point = 0 #which column contains Backers's real names with open(documet,'rb') as csvfile: backer_list = csv.reader(csvfile, delimiter=',', quotechar='|') for row in backer_list: row_length = len(row) - 1 if row[1] == "Backer Name": # Is this the header row? name_point = row.index("Name")+1 else: # This row contains Backer's info if row[row_length] == "Yes" or row[row_length] == "yes": if len(row) > (name_point): """Some backers did not fill out the forms so this checked whether there was an empty row or not""" print row[name_point] elif row[row_length] == "No" or "no": """This elif statement is not entirely necessary""" pass def generate_list(tiers): for i in range(len(reward_tier)): retrieve(tiers[i]) generate_list(reward_tier)
A list of Backer’s name came out which was turned into this list and those who did not want to be included were not. Problem solved.